# Decimal code

## Encoding Method

Each number of etch system is represented by 4-bit binary digital, each with a fixed weight. Therefore, it is called it as a weight code or weighted code. 8421 The weight of the code from the high to ten:

,
,
,
. Therefore, 1-bit decimal number D corresponding to 4-bit binary
can be represented as:

Each decimal number indicated by 8421 yards and Ordinary binary representation is exactly the same, or, the binary code corresponding to each decimal number is the binary number of the decimal number. Therefore, in the 8421 code, there are six codes (1010, 1011, 1111), which are impossible, also known as illegal 8421 codes.

Any decimal number is to be written into an 8421 code representation, as long as the number of the decimal number is converted into a corresponding 8421 yard, such as

.

In turn, the decimal number of 8421 yards indicated, or conveniently convert into ordinary decimal number, such as

.

## Form

### Compressed BCD code

Compression BCD code (or combined BCD code), which features 4-bit binary number

To represent a decimal number, that is, one byte represents two decimal numbers. If the compression BCD code of the decimal number 57 is

01010L1Lb; the binary number 10001001, the compression BCD code is used as a decimal number 89.

### Non-compressed BCD code

Non-compressed BCD code (or non-combined BCD code) indication is characterized by using an 8-bit binary number to represent a decimal number, that is, one byte representation 1 digit decimal number, and only 4 digits of each byte is 0 ~ 9, and 4 digits are set to 0. If the decimal number 89, the non-compressed BCD code is expressed as the binary number is 00001000 00001001.

The conversion between the BCD code and the decimal number is easy to implement, such as the compressed BCD code is 1001 0101 0011.0010 0111, its decimal value is 953.27.

BCD code can intuitively express a decimal number, and it is easy to achieve mutual conversion with the ASCII code, which is easy to input, and output.

Related Articles