BCD code is often used in PLC Data conversion. What is BCD code and compressed BCD code? What is the difference between the two?
In a digital system, all kinds of data must be converted to binary code for processing. People are used to using decimal numbers. Therefore, the input and output of the digital system still use decimal numbers, in this way, a four-digit binary number is used to represent a single-digit decimal number. The binary code used to represent a decimal number is called binary coded decimal ), BCD code for short. It has a binary number to meet the requirements of the digital system, and has a decimal character (only 10 valid states ). In some cases, computers can also directly perform operations on the numbers in this form. Common BCD codes indicate the following types.
8421bcd Encoding
This is the most widely used BCD code and the right code. Each of them has 8, 4, 2, and 1 permissions (starting from the most effective level to the lowest valid bit.
For example, write the 8421bcd code corresponding to the decimal number 563.97d.
563.97d = 0101 0110 0011. 1001 01118421bcd
In this example, write the number of decimal numbers corresponding to the 8421bcd code 1101001.010118421bcd.
1101001.010118421bcd = 0110 1001. 0101 10008421bcd = 69.58d
When using 8421bcd, you must note that there are only 10 valid codes, that is, 0000 ~ 1001. The remaining six Codes of the four-digit binary numbers are 10, and 1111.
2421bcd Encoding
The 2421bcd code is also a type of authorization code. The weights from the high position to the low position are 2, 4, and 2, respectively. It can also use four binary numbers to represent a decimal number. The following table lists the encoding rules.
3 more codes
The remainder 3 code is also a type of BCD code, but it does not have a permission Code. However, because the difference between the 8421bcd code corresponding to each code is 3, it is called the remainder 3 code, which is generally used less, therefore, it is necessary to make a general understanding. The specific encoding is shown in the following table.
Common BCD encoding tables
Number of decimal places 8421bcd code 2421bcd code plus 3 code
0 0000 0000 0011
1 0001 0001 0100
2 0010 0010 0101
3 0011 0011 0110
4 0100 0100 0111
5 0101 1011 1000
6 0110 1100 1001
7 0111 1101 1010
8 1000 1110 1011
9 1001 1111 1100
10 0001,0000 0001,0000 0100,0011
Non-compressed and compressed:
BCD is divided into two types: Non-compressed and compressed.
The preceding 81-second format is saved as "", but the "81h" format is saved as "81h"
(Stored in hexadecimal format directly ).
The non-compressed BCD code is only valid for the lower four BCD digits, while the compressed BCD code is used for the higher four BCD digits. That is to say, one byte has two BCD codes.
BCD uses 0 and 1 as decimal symbols. For example, 0000 represents 0, represents 1, represents 2.
The sub-1234 is expressed as 0001001000110100, while the compressed BCD is expressed as 0, 01 is expressed as 1,
10 indicates 2,110 indicates 3, but the compressed BCD is not fixed, depending on the situation.
Is to use the least number of digits to represent as many as possible.
Http://blog.gkong.com/more.asp? Id = 1219 & name = zhyo720211