当前位置:网站首页>BCD code Baidu Encyclopedia
BCD code Baidu Encyclopedia
2022-07-04 12:20:00 【Bear coder】
BCD code (Binary-Coded Decimal), use 4 position Binary number To express 1 position Decimal number Medium 0~9 this 10 Number , It's a binary form of digital coding , use Binary coded decimal system Code .BCD This form of coding uses four bits to store a decimal number , send Binary system and Decimal system The conversion between can be carried out quickly . This coding technique is most commonly used in the design of accounting systems , Because the accounting system often needs to accurately calculate a long string of numbers . Compared with the general floating-point type Notation , use BCD code , The accuracy of the values can be preserved , It can also avoid the time spent by the computer in floating-point operation . Besides , For other calculations that require high accuracy ,BCD Coding is also very common .
brief introduction
BCD Code is also called binary code decimal number ,BCD Codes can be divided into Right code and Unauthorized code Two types of . among , Common have the right to BCD The code has 8421 code 、2421 code 、5421 code , Have no right BCD There are more than yards 3 code 、 more than 3 Cyclic code 、 Gray code .8421BCD Code is the most basic and commonly used BCD code , It is similar to a four bit natural binary code , Your weight is 8、4、2、1, So it's called right BCD code .5421BCD Code and 2421BCD Both codes are entitled codes , Their weights from high to low are 5、4、2、1 and 2、4、2、1. more than 3 Code is by 8421 Code plus 3 After the formation of , It's a kind of “ Yes 9 Self complement of ”. more than 3 Cyclic code is a kind of variable weight code , Each bit does not represent a fixed value in different codes , The main feature is that there is only one bit of state difference between two adjacent codes . Gray code ( Also called cyclic code ) By Bell Laboratories FrankGray stay 1940 Put forward in , be used for PCM Method to prevent errors when transmitting signals . Gray code is a set of numbers , It is unauthorized code , Its two adjacent codes have only one different value . more than 3 The cyclic code is taken 4 Ten codes in the bit gray code , It also has the characteristics of adjacency [1] .
Category
8421
8421 BCD Code is the most basic and commonly used BCD code , It is similar to a four bit natural binary code , Everyone A weight by 8、4、2、1, So it's called right BCD code . And four bit natural binary code is different , It only uses the first four bit binary code 10 Group code , The box 0000~1001 Respectively represents its corresponding Decimal number , The remaining six sets of codes are not used .
5421 and 2421
5421 BCD Code and 2421 BCD Code is entitled BCD code , Their weights from high to low are 5、4、2、1 and 2、4、2、1. These two kinds of rights BCD In code , There are two kinds of decimal digits weighting Method , for example ,5421 BCD The number in the code 5, You can use 1000 Express , It can also be used. 0101 Express ;2421 BCD The number in the code 6, You can use 1100 Express , It can also be used. 0110 Express . This explanation 5421 BCD Code and 2421 BCD The coding scheme of code is not unique , surface 1-2 Only one coding scheme is listed .
The above table 2421 BCD The code 10 Among the numbers ,0 and 9、1 and 8、2 and 7、3 and 6、4 and 5 Exactly one of the corresponding bits of the code is 0 when , The other is 1. It's called 0 and 9、1 and 8 Each other Inverse code .
more than 3 code
more than 3 Code is 8421 BCD Add... To each code group of the code 3(0011) Formed . Commonly used in BCD In the operation circuit of code .
more than 3 Cyclic code
more than 3 Cyclic code Is the unauthorized code , That is... In each code 1 and 0 There is no exact weight , The whole code directly represents a value . The main advantage is that there is only one bit change in adjacent codes , The generation of transition code is avoided “ noise ”.
Gray code
Gray code ( Gray code ) Also known as Cyclic code , In the coding of a set of numbers , If the code of any two adjacent numbers is only one binary number different [2] .Gray There are many coding schemes , Typical Gray The code is shown in the following table . It can be seen from the table that , This code has the characteristics of unit distance code , Another feature is that it has reflective properties , That is, as shown in the table Axis of symmetry As a boundary , In addition to the highest complementary reflection , The remaining low order numbers are mirrored symmetrically along the axis of symmetry . Using this reflection characteristic, it is convenient to form Gray code .
Encoding mode
Most commonly used BCD code , Is the use of "0" to "9" The binary code of these ten values . This kind of coding , It's called “8421 code ”( What we say everyday BCD Code mostly refers to 8421BCD Code form ). in addition to , Corresponding to different needs , Everyone has also developed different coding methods , To adapt to different needs . These codes , It can be roughly divided into weighted code and unauthorized code : Entitled BCD code , Such as :8421( The most commonly used )、2421、5421…
Have no right BCD code , Such as : more than 3 code 、 Gray code …( Be careful : Gray code is not BCD code ) Here are three common BCD Coding comparison .
Decimal number 8421-BCD code more than 3-BCD code 2421-A code
(M10) DCBA C3C2C1C0 a3a2a1a0
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 / 1 0 1 1
6 - 0 1 1 0 / 1 0 0 1 / 1 1 0 0
7 - 0 1 1 1 / 1 0 1 0 / 1 1 0 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
Commonly used BCD code
Decimal number | 8421 code | 5421 code | 2421 code | more than 3 code | more than 3 Cyclic code |
---|---|---|---|---|---|
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 |
give an example
A binary unsigned number 11101010, Convert to three digits Uncompressed BCD Count , Press hundreds 、 Ten Bit and The order of bits indicates , Should be C.
A.00000001 / 00000011 / 00000111 B. 00000011 / 00000001 / 00000111
C.00000010 / 00000011 / 00000100 D. 00000011 / 00000001 / 00001001
Explain :(1)11101010 Convert to Decimal system :234
(2) Press hundreds 、 The order of ten bits and one bit indicates , Should be C.
Note appended : Compress BCD code And Uncompressed BCD code The difference between —— Compress BCD Every bit of the code uses 4 Bit binary representation , A byte represents two bits Decimal number . for example 10010110B Represents a decimal number 96D; Uncompressed BCD code use 1 Bytes represent a decimal number , The senior four are always 0000, low 4 Bit 00001001 Express 09. for example 00001000B Represents a decimal number 8.
BCD Algorithm of code
BCD Operation rules of code :BCD The code is a decimal number , When the arithmetic unit adds and subtracts the data , They are processed according to binary operation rules . such , When will BCD When the code is transmitted to the arithmetic unit for operation , The result needs to be corrected . The revised rule is : When two BCD Code addition , If the sum is equal to or less than 1001( namely Decimal number 9), No correction is required ; If the sum is 1010 To 1111( Hexadecimal number 0AH~0FH) Between , You need to add 6 Amendment ; If you add , Standard produces carry , Also need to add 6 Amendment . And the reason for that is , Press the machine Binary system Add up , therefore 4 position Binary number When adding , Is in accordance with the “ Every 16 to one ” The principle of operation , And in essence 2 Add decimal numbers , You should press “ Dot into one ” The principles of add ,16 And 10 Difference between 6, So when and exceed 9 There may be rounding , All need to be added 6 Amendment . Here's an example .
【 example 1.3】 Need to fix BCD Examples of code operation values .
(1) Calculation 5+8;(2) Calculation 8+8
Explain :(1) take 5 and 8 With 8421 BCD Input machine , Then the operation is as follows :
0 1 0 1
+) 1 0 0 0
1 1 0 1 The result is greater than 9
+) 0 1 1 0 Add 6 correct
1 0 0 1 1 namely 13 Of BCD code
The result is 0011, namely Decimal number 3, It also generates carry .5+8=13, The conclusion is correct .
(2) take 8 With 8421 BCD Input machine , Then the operation is as follows :
1 0 0 0
+)1 0 0 0
1 0 0 0 0 Generating carry
+)0 1 1 0 Add 6 correct
1 0 1 1 0 16 Of BCD code
The result is 0110, namely Decimal system Of 6, And generate carry .8+8=16, The conclusion is correct .
Microcomputer principle code : (AL=BCD 5,BL=BCD 8) set up AH=0, be
ADD AL,BL
AAA
The result is AX=0103H, Represents uncompressed Decimal number ,CF=1,AF=1,AH=1,AL=3
Use AAA Instructions , It is not necessary to mask the high half byte , Just execute immediately after adding AAA Instructions , Then you can be in AX Get a correct uncompressed decimal number in
边栏推荐
- [directory] search
- IO stream ----- open
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
- Haproxy cluster
- Automatic translation between Chinese and English
- The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history
- OSI seven layer model & unit
- Summary of Shanghai Jiaotong University postgraduate entrance examination module firewall technology
- Foreach (system.out:: println) usage
- Configure SSH certificate login
猜你喜欢
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
os. Path built-in module
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
Source code analysis of the implementation mechanism of multisets in guava class library
Process communication and thread explanation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
Method of setting default items in C # ComboBox control code
DDS-YYDS
随机推荐
Data transmission in the network
01. Basics - MySQL overview
Some summaries of the 21st postgraduate entrance examination 823 of network security major of Shanghai Jiaotong University and ideas on how to prepare for the 22nd postgraduate entrance examination pr
2021-08-09
Reptile learning 4 winter vacation series (3)
Detailed explanation of classic process synchronization problems
Entitas learning [iv] other common knowledge points
Pat 1059 prime factors (25 points) prime table
Foreach (system.out:: println) usage
Experiment 7. IPv6
The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history
Games101 Lesson 8 shading 2 Notes
How to disable debug messages on sockjs stomp - how to disable debug messages on sockjs Stomp
Properties and methods of OS Library
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
Video analysis
Snowflake won the 2021 annual database
Introduction of network security research direction of Shanghai Jiaotong University
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)