BCD code (8421 encoding) __ Encoding

Source: Internet
Author: User

A 4-bit binary number is used to represent the 0~9 of the 1-bit decimal number, which is called the BCD code, which is the 10 digital. binary-coded decimal, or BCD, is called BCD or two-decimal code, also known as the binary number of binary numbers. is a binary encoded form of a binary coded decimal code.

Defining the BCD code this type of encoding uses four bits to store a decimal digit, making the conversion between binary and decimal fast. This coding technique is most commonly used in the design of accounting systems, because the accounting system often requires accurate calculations of long numbers of strings. Relative to the general floating-point notation, the use of BCD code, both to preserve the accuracy of the numerical value, but also to avoid the computer as a floating-point operation of the time spent. In addition, BCD coding is also common for other calculations that require high accuracy.

Since there are 0, 1, 2 、......、 90 digits in decimal numbers, at least 4-bit binary codes are required to represent 1-bit decimal numbers. 4-bit binary code common 2^4=16 code group, in these 16 kinds of code, you can choose 10 kinds to represent 10 decimal digits, a total of n=16. /(16-10). Approximately equals 2.9 times 10 of the 10-way scheme. Common BCD codes are listed at the end. Common BCD Encoding Method

The most commonly used BCD code is represented by a binary code of 10 values, "0" through "9". This coding method, called "8421 yards" in mainland China. In addition, different coding methods have been developed to suit different needs. These codes can be roughly divided into two types: the Power code and the Unauthorized code.

The right BCD code, such as: 8421 (most commonly used), 2421, 5421 ...

Not authorized BCD code, such as: 3 yards, Gray code ...

The following is a comparison of three common BCD encodings.

Decimal number 8421-BCD Code 3-BCD code 2421-A code

(M10) d C b a C3 C2 C1 C0 A3 A2 A1 A0

0 0 0 0 0 0 0 1 1 0 0 0 0

1 0 0 0 1 0 1 0 0 0 0 0 1

2 0 0 1 0 0 1 0 1 0 0 1 0

3 0 0 1 1 0 1 1 0 0 0 1 1

4 0 1 0 0 0 1 1 1 0 1 0 0

5 0 1 0 1 1 0 0 0 0 1 0 1

6 0 1 1 0 1 0 0 1 0 1 1 0

7 0 1 1 1 1 0 1 0 0 1 1 1

8 1 0 0 0 1 0 1 1 1 1 1 0

9 1 0 0 1 1 1 0 0 1 1 1 1

  Common BCD Code

Decimal number 8421 yards 5421 yards 2421 yards more than 3 yards more than 3 cycle codes

0 0000 0000 0000 0011 0010

1 0001 0001 0001 0100 0110

2 0010 0010 0010 0101 0111

3 0011 0011 0011 0110 0101

4 0100 0100 0100 0111 0100

5 0101 1000 1011 1000 1100

6 0110 1001 1100 1001 1101

7 0111 1010 1101 1010 1111

8 1000 1011 1110 1011 1110

9 1001 1100 1111 1100 1010

----------------------- edit this paragraph features

8421 code intuitive, good understanding.

Numbers greater than 5 in both 5421 yards and 2421 yards are 1 high and 5 below 0.

The remaining 3 yards is 8421 yards plus 3, there is overflow and under overflow space.

Gray code adjacent to 2 number of three bits are the same, only one bit different.

———————————————————— What is a BCD code

BCD code also called 8421 yards is the decimal number in the form of 8421 to expand into binary, you know that decimal is 0~9 10 numbers, which 10 number each has its own 8421 yards:

0=0000

1=0001

2=0010

3=0011

4=0100

5=0101

6=0110

7=0111

8=1000

9=1001

As an example:

321 of 8421 yards is

3 2 1

0011 0010 0001

Reason: 0011=8x0+4x0+1x2+1x1=3 0010=8x0+4x0+2x1+1x0=2. 0001=8x0+4x0+2x0+1x1=1

Specific:

BCD Code is a four-bit binary code, that is, the decimal number into binary, but with the ordinary conversion is a little different, each decimal number 0-9 corresponds to a four-bit binary code, the corresponding relationship is as follows: decimal 0 corresponds to binary 0000; decimal 1 corresponds to binary 0001. ..... 9 1001 The next 10 will have two of the above code to indicate 10 means that the BCD code is met 00010000 to produce carry, not like ordinary binary code, to 1001 to produce carry 10000 Example

A binary unsigned number 11101010, converted to three-bit uncompressed BCD, expressed in the order of the Hundred, 10, and single digits, should be <u>__c</u>__.

a.00000001 00000011 00000111 B. 00000011 00000001 00000111

c.00000010 00000011 00000100 D. 00000011 00000001 00001001

Solution: (1) 11101010 convert to decimal: 234

(2) According to the Order of hundred, 10 and single digits, should be <u>__c</u>__.

Note: The difference between a compressed BCD code and a non-compressed BCD code-Each bit of the compressed BCD code is represented by a 4-bit binary representation, and a byte represents a two-bit decimal number. For example 10010110B means decimal number 96D, non-compressed BCD code with 1 bytes for a decimal number, high four bits always 0000, low 4 bits 0000~1001 represents 0~9. For example, 00001000B means decimal number 8.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.