The BCD code is actually the number in the digital circuit that was previously said to represent a number in a 0-9 with a 4-bit binary value.
Example: 0000=0 0001=1 0010=2 0011=3
This means that if a number is used as a BCD code, for example: 11 22
Then he should expand to: 00010001 00100010
That corresponds to decimal: 17 34
So a BCD? The idea of turning into decimal data is to separate the BCD code from each number, such as the 11 above
Separate the 10-bit 1 and move the 4-bit right by the previous 10-digit number. Decimal to BCD code
Thought: This decimal number is expressed in binary notation, the number of high 4 digits is how many * 10 plus the lower four bits represent
The numbers, C programs are as follows:
#define BCD_TO_DECIMAL (BCD) (((BCD) >> 4) + (BCD)% 10);
#define DECIMAL_TO_BCD (int dec) ((0xf0 & (Dec) >> 4) *10 + (0x0f & (DEC)))
BCD code converted to decimal or decimal to BCD code