博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bcd码二进制转十进制_二进制编码的十进制(BCD码)及其加法
阅读量:2532 次
发布时间:2019-05-11

本文共 4755 字,大约阅读时间需要 15 分钟。

bcd码二进制转十进制

Prerequisite:

先决条件:

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表示被给定为011070111。

BCD Addition | Example 1

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中将67相加时,我们得到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表示的87651000 0111 0110 0011,39430011 1001 0100 0011

BCD Addition | Example 2

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.

首先,我们将对两个数字进行正常的二进制加法运算,现在我们看到11001010是非法状态,也是从LSB侧开始的第三组4位,即0000的进位为1 。 因此,为了更正,我们必须在所有三个组中添加0110 。 因此,我们得到正确的结果为0001 0010 0111 0000 1000 ,它等于十进制数系统中的(12708) 10 ,这就是我们加上(8765) 10 +(3943) 10 =(12708) 10的结果 。 因此,我们的结果也得到了验证。

翻译自:

bcd码二进制转十进制

转载地址:http://rixzd.baihongyu.com/

你可能感兴趣的文章
阶段3 2.Spring_03.Spring的 IOC 和 DI_6 spring中bean的细节之三种创建Bean对象的方式
查看>>
阶段3 2.Spring_04.Spring的常用注解_3 用于创建的Component注解
查看>>
阶段3 2.Spring_04.Spring的常用注解_2 常用IOC注解按照作用分类
查看>>
阶段3 2.Spring_09.JdbcTemplate的基本使用_5 JdbcTemplate在spring的ioc中使用
查看>>
阶段3 3.SpringMVC·_07.SSM整合案例_02.ssm整合之搭建环境
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第1节零基础快速入门SpringBoot2.0_3、快速创建SpringBoot应用之手工创建web应用...
查看>>
阶段3 3.SpringMVC·_07.SSM整合案例_04.ssm整合之编写SpringMVC框架
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第1节零基础快速入门SpringBoot2.0_5、SpringBoot2.x的依赖默认Maven版本...
查看>>
阶段3 3.SpringMVC·_07.SSM整合案例_08.ssm整合之Spring整合MyBatis框架
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_9、SpringBoot基础HTTP其他提交方法请求实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_12、SpringBoot2.x文件上传实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_19、SpringBoot个性化启动banner设置debug日志...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_20、SpringBoot2.x配置全局异常实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第5节 SpringBoot部署war项目到tomcat9和启动原理讲解_23、SpringBoot2.x启动原理概述...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_21、SpringBoot2.x配置全局异常返回自定义页面...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_32..SpringBoot2.x持久化数据方式介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_34、SpringBoot整合Mybatis实操和打印SQL语句...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_35、事务介绍和常见的隔离级别,传播行为...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_37、分布式缓存Redis介绍...
查看>>