Our Brands

Welcome to the Schneider Electric Website

Welcome to our website.
        
How can we help you today?
TelePACE Studio BCD to Integer

Question:

Is it possible to convert a 4 digit BCD (binary-coded decimal) register into an integer value?

Solution:

A binary coded decimal is where each digit is represented by a fixed number of bits (typically 4). BCD takes advantage of the fact that any one decimal number can be represented by a 4-bit pattern. The most common way of encoding a decimal digit is by its corresponding four-bit binary value. 

Simple BCD, also called BCD 8421 encoding is the most common encoding method.

Most BCD values will typically encode 2 digits within a byte (8 bits). This is sometimes called a packed BCD.

Now a 16-bit SCADAPack register in TelePACE can store an unsigned integer between 0-65535. The same 16-bit register can store a BCD value between 0-9999. 

The following TelePACE code takes a single register with a BCD value and converts it to an unsigned integer in the SCADAPack. It uses modular math to extract the value for each digit. It then multiplies and adds the pieces back together as an unsigned integer.

Modular math operations to take a BCD value and convert it to an unsigned integer.

A hexadecimal BCD value is input into register 41000 in the decimal range of 0-9999. Let's call it WXYZ. The SCADAPack will interpret the BCD value as an incorrect unsigned integer. 

  • Register 41001 MODU 4096 gives the remainder XYZ and puts it in register 43005
  • Register 41001 DIVU 4096 gives the number of thousands W
  • Register 43005 MODU 256 gives the remainder YZ and stores it in register 43003
  • Register 43005 DIVU 256 gives the number of hundreds X
  • Register 43003 MODU 16 gives the remainder Z and stores it in register 43001
  • Register 43003 DIVU 16 gives the number of tens Y

Once the values are determined for W, X, Y and Z, they can be combined together to form an unsigned integer.

This logic recombines the digit values calculated earlier and recreates the value as an unsigned integer  (W*1000) + (X*100) + (Y*10) + Z 

  • This logic calculates (W*1000) + (X*100) + (Y*10) + Z and stores the result in register 42001

 

Schneider Electric Philippines

Explore more
Range:
Users group

Discuss this topic with experts

Visit our Community for first-hand insights from experts and peers on this topic and more.
Explore more
Range:
Your browser is out of date and has known security issues.

It also may not display all features of this website or other websites.

Please upgrade your browser to access all of the features of this website.

Latest version for Google Chrome, Mozilla Firefox or Microsoft Edgeis recommended for optimal functionality.
Your browser is out of date and has known security issues.

It also may not display all features of this website or other websites.

Please upgrade your browser to access all of the features of this website.

Latest version for Google Chrome, Mozilla Firefox or Microsoft Edgeis recommended for optimal functionality.