bcd码二进制转十进制
Prerequisite: Number systems
先决条件: 数字系统
BCD Code (8421 Code): In BCD 8421 code, each decimal digit is represented using a 4-bit binary number. The 4-bit binary numbers have their weights attached as 8, 4, 2, 1 from MSB to LSB side. Since the weights are attached to it comes in the category of weighted codes and is also sequential.
BCD代码(8421代码) :在BCD 8421代码中 ,每个十进制数字均使用4位二进制数表示。 从MSB到LSB,4位二进制数的权重分别为8、4、2、1。 由于权重是附加的,因此它属于加权代码类别,并且是顺序的 。
In a digital system that accepts only binary numbers in form of 0 and 1, the only way to interpret decimal numbers is its conversion from decimal to binary and vice-versa which is a slow process and it also requires a huge electronic circuitry. So, we use BCD numbers. Also, the sequential nature of BCD numbers makes it advantageous for performing arithmetic operations.
在仅接受0和1形式的二进制数字的数字系统中,解释十进制数字的唯一方法是将其从十进制转换为二进制,反之亦然,这是一个缓慢的过程,并且还需要庞大的电子电路。 因此,我们使用BCD号码。 而且,BCD编号的顺序性质使其在执行算术运算时具有优势。
Although, there are many advantages there are some disadvantages too such as:
尽管有很多优点,但也有一些缺点,例如:
BCD codes are more inefficient than usual binary codes. Usually, in binary numbers, we represent (13)10 = (1101)2 i.e., we require 4-bits but in BCD notation (13)10 is represented as (0001 0011). Here, we require 8-bits to represent the same 13.
BCD代码比普通的二进制代码效率低。 通常,在二进制数中,我们表示(13) 10 =(1101) 2,即,我们需要4位,但在BCD表示法中, (13) 10表示为(0001 0011) 。 在这里,我们需要8位来表示相同的13 。
Another disadvantage is that arithmetic operations become more complex as compared to the usual binary numbers because, in BCD numbers, we have 6 illegal states as 1010, 1011, 1100, 1101, 1110 and 1111 which are not part of 8421 BCD system.
另一个缺点是,与通常的二进制数相比,算术运算变得更加复杂,因为在BCD数中,我们有6个非法状态,例如1010、1011、1100、1101、1110和1111 ,它们不是8421 BCD系统的一部分。
The following table describes the relation between Decimal, Binary and 8421 BCD numbers.
下表描述了十进制,二进制和8421 BCD编号之间的关系。
Decimal Numbers | Binary Numbers | 8421 BCD Numbers |
---|---|---|
0 | 0000 | 0000 |
1 | 0001 | 0001 |
2 | 0010 | 0010 |
3 | 0011 | 0011 |
4 | 0100 | 0100 |
5 | 0101 | 0101 |
6 | 0110 | 0110 |
7 | 0111 | 0111 |
8 | 1000 | 1000 |
9 | 1001 | 1001 |
10 | 1010 | 0001 0000 |
11 | 1011 | 0001 0001 |
12 | 1100 | 0001 0010 |
13 | 1101 | 0001 0011 |
14 | 1110 | 0001 0100 |
15 | 1111 | 0001 0101 |
... | ... | ... |
... | ... | ... |
... | ... | ... |
小数 | 二进制数 | 8421 BCD编号 |
---|---|---|
0 | 0000 | 0000 |
1个 | 0001 | 0001 |
2 | 0010 | 0010 |
3 | 0011 | 0011 |
4 | 0100 | 0100 |
5 | 0101 | 0101 |
6 | 0110 | 0110 |
7 | 0111 | 0111 |
8 | 1000 | 1000 |
9 | 1001 | 1001 |
10 | 1010 | 0001 0000 |
11 | 1011 | 0001 0001 |
12 | 1100 | 0001 0010 |
13 | 1101 | 0001 0011 |
14 | 1110 | 0001 0100 |
15 | 1111 | 0001 0101 |
... | ... | ... |
... | ... | ... |
... | ... | ... |
Example 1: Represent (28)10 and (53)10 in 8421 BCD notation
示例1:以8421 BCD表示法表示(28) 10和(53) 10
Solution:
解:
(28)10 in BCD notation can be represented as (0010 1000).
(28) BCD表示法中的10可以表示为(0010 1000) 。
Similarly, (53)10 in BCD notation can be represented as (0101 0011).
类似地,BCD表示法中的(53) 10可以表示为(0101 0011) 。
BCD加法 (BCD Addition)
The addition of BCD numbers is slightly different from binary addition. Here, the rules of binary addition are partially applicable only to the individual 4-bit groups. The BCD addition, is thus carried out by individually adding the corresponding 4-bit groups starting from the LSB side and if there is a carry to the next group, or if the result belongs to any of the 6 illegal states than we add 610(0110) to the sum term of that group and resulting carry is added in the next group.
BCD编号的加法与二进制加法略有不同。 在此,二进制加法规则仅部分适用于各个4位组。 因此, BCD加法是通过从LSB端开始逐个添加对应的4位组来进行的,如果下一个组有进位,或者结果属于6个非法状态中的任何一个,则我们加6 10 (0110)至该组的总和,并在下一组中添加产生的进位。
Example: Perform BCD Addition of 6 and 7.
示例:执行6和7的BCD加法。
Solution: BCD representation of 6 is given as 0110 and for 7 it is 0111.
溶液:6 BCD表示被给定为0110和7是0111。
When we add 6 and 7 in BCD, we get 1101 which is an invalid state therefore, we add 0110 (6) to the sum to get correct result which is 0001 0011 (13).
当在BCD中将6和7相加时,我们得到1101 ,这是一个无效状态,因此,我们将0110(6)添加到总和中以获得正确的结果0001 0011(13) 。
Example 2: Perform BCD Addition of 8765 and 3943.
示例2:执行8765和3943的BCD加法。
Solution:
解:
BCD representation of 8765 is given as 1000 0111 0110 0011 and for 3943 it is 0011 1001 0100 0011.
BCD表示的8765为1000 0111 0110 0011,3943为0011 1001 0100 0011 。
Firstly, we will perform a normal binary addition of two numbers now we see 1100 and 1010 which are illegal states also the third group of 4-bits from LSB side i.e., 0000 has a carry 1 to the next group. So, for correction, we have to add 0110 to all three groups. Thus, we get the correct result as 0001 0010 0111 0000 1000 which is equivalent to (12708)10 in decimal number system and this is what we get on adding (8765)10 + (3943)10 = (12708)10. Hence, our result is also verified.
首先,我们将对两个数字进行正常的二进制加法运算,现在我们看到1100和1010是非法状态,也是从LSB侧开始的第三组4位,即0000的进位为1 。 因此,为了更正,我们必须在所有三个组中添加0110 。 因此,我们得到正确的结果为0001 0010 0111 0000 1000 ,它等于十进制数系统中的(12708) 10 ,这就是我们加上(8765) 10 +(3943) 10 =(12708) 10的结果 。 因此,我们的结果也得到了验证。
翻译自: https://www.includehelp.com/basics/binary-coded-decimal-bcd-code-and-its-addition.aspx
bcd码二进制转十进制