bcd码二进制转十进制_二进制编码的十进制(BCD码)及其加法

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 NumbersBinary Numbers8421 BCD Numbers
000000000
100010001
200100010
300110011
401000100
501010101
601100110
701110111
810001000
910011001
1010100001 0000
1110110001 0001
1211000001 0010
1311010001 0011
1411100001 0100
1511110001 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的结果 。 因此,我们的结果也得到了验证。

翻译自: https://www.includehelp.com/basics/binary-coded-decimal-bcd-code-and-its-addition.aspx

bcd码二进制转十进制

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/379423.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SVN服务器部署

一、SVN版本控制器 Subversion就是一款实现版本控制的工具软件,通常也成为版本控制器,简称SVN。 Subversion是Apache软件基金会组织下的一个项目 SVN基本操作: checkout(检出):将一个服务端创建好的项目…

rtmp流\http流测试地址

测试方式:ffplay rtmp://58.200.131.2:1935/livetv/cctv1 rtmp: CCTV-1综合:rtmp://58.200.131.2:1935/livetv/cctv1 CCTV-2财经:rtmp://58.200.131.2:1935/livetv/cctv2 CCTV-3综艺:rtmp://58.200.131.2:1935/livetv/cctv3 CCTV-4中文国际:rtmp://58.2…

LINQ to XML:如何读写XCData

using System;using System.Xml.Linq;namespace ConsoleApplication1 {class Program{static void Main(string[] args){//写入CDATA元素块var doc new XElement("Test",new XElement("User",new XAttribute("name", "chenxizhang"),…

C#中的结构和类之间的区别

C#类和结构 (C# class and structure) In C# and other programming languages, structure and classes are used to define a custom data type, that we can organize according to our need with different types of variables, methods etc. 在C#和其…

[转载]SQL Plus 一些使用技巧

原文地址:SQL Plus 一些使用技巧作者:☆水『若寒Sql*plus的使用 Sql*plus介绍 Sql*plus是oracle提供的一个工具程序,既可以在oracle服务器使用,也可以在oracle客户端使用。在windows下分两种,sqlplus.exe是命令行程序&…

云服务器(Centos)部署SVN

1,安装svn yum install subversion 2,查看版本号 svnserve --version 3,创建SVN版本库(在var/svn 文件夹下) 新建文件夹 mkdir -p /var/svn/svnrepos 创建版本库 svnadmin create /var/svn/svnrepos 4,修改…

ffmpeg命令提取像素格式

1: 提取yuv格式:不修改宽高 取3秒 ffmpeg -i test_1920x1080.mp4 -t 3 yuv420p_orig.yuv ffmpeg -i test_1920x1080.mp4 -t 3 -pix_fmt yuv420p yuv420p_orig.yuv 可以使用ffplay播放:ffplay -video_size 1920x1080 yuv420p_orig.yuv 提取y…

Javascript(js)使用function定义构造函数

Javascript并不像Java、C#等语言那样支持真正的类。但是在js中可以定义伪类。做到这一点的工具就是构造函数和原型对象。首先介绍js中的构造函数。 Javascript中创建对象的语法是在new运算符的后面跟着一个函数的调用。如 1 varobj newObject();2 vardate newDate();运算符new首…

错误:将字符串分配给C中的char变量| 常见的C程序错误

If you assign a string to the character variable, it may cause a warning or error (in some of the compilers) or segmentation fault error occurs. 如果将字符串分配给字符变量,则可能会导致警告或错误(在某些编译器中)或发生分段错误。 Consider the code…

【转】用BibTeX 写 Reference

BibTeX 是一种格式和一个程序, 用于协调LaTeX的参考文献处理,BibTeX 使用数据库的的方式来管理参考文献.,BibTeX 文件的后缀名为 .bib。 例子: article{name1, author {作者, 多个作者用 and 连接}, title {标题}, journal {期…

计算机二级C语言易混淆的区别

1,if(a1)与if(a1)的区别 首先,if(a1) 等价于 a1;if(a); 而a 1,是判断a是不是为1; if(sq)里面的分为两种情况,一种是sq为0,不执行if里面的代码内容;另一种是sq不为0,执行里面的代码内…

ffmpeg命令mp3中提取pcm格式

原mp3文件: ffmpeg -i buweishui.mp3 -ar 48000 -ac 2 -f s16le 48000_2_s16le.pcm (这可能是pcm原格式查不到什么信息但是可以播放的:ffplay -ar 48000 -ac 2 -f s16le 48000_2_s16le.pcm) ffmpeg -i buweishui.mp3 -ar 48000 -ac 2 -samp…

C++ STL map的使用

1、map简介 map是一类关联式容器。它的特点是增加和删除节点对迭代器的影响很小,除了那个操作节点,对其他的节点都没有什么影响。对于迭代器来说,可以修改实值,而不能修改key。 2、map的功能 自动建立Key - value的…

bfs广度优先搜索算法_图的广度优先搜索(BFS)

bfs广度优先搜索算法What you will learn? 您将学到什么? How to implement Breath first search of a graph? 如何实现图的呼吸优先搜索? Breadth First Search is a level-wise vertex traversal process. Like a tree all the graphs have verte…

考研C++必刷题(一)

【程序1】 题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 解题思路: 利用三层循环,分别控制百位十位个位,若百位十位个位有重复的,则不输出即可。 代…

关于计算机存储单位?

关于计算机存储单位? 计算机只能识别二进制。(1010100110. . . ) 1字节 8bit(8比特)–>1byte 8bit 1bit 就是一个 1 或 0 1KB 1024byte byte是[-128 ~ 127],共可以标识256个不同的数字。 byte类型的最大值是怎么计算出来的…

ffmpeg 命令转封装

1: 改变编码格式 原mp4文件:视频是h264 音频是aac 视频转成h265,音频转成mp3(容器为mkv,有些容器不一定支持放h265的) ffmpeg -i test_60s.mp4 -vcodec libx265 -acodec libmp3lame out_h265_mp3.mkv 播放&#xff1a…

Delphi 2010 DataSnap封装COM对象

在Delphi 2010中,DataSnap已完全可以不使用COM了.想起在windows上配置COM,就麻烦的很,如果在本机还好说,在远程要涉及到权限等诸多问题(用SocketConnection要方便一些). 如果早期写的程序中有许多COM对象,我们可以通过DataSnap的封装,使用适配器模式简单地封装一下,那么在客户端…

JavaScript中带有示例的Math.PI属性

JavaScript | Math.PI属性 (JavaScript | Math.PI Property) Math.PI is a property in math library of JavaScript that is used to find the value of PI(π) which is a mathematical constant whose value is 3.141. It is generally used to solve problems related to c…

设计模式笔记——Bridge

桥接模式Bridge Pattern 组合关系(实心菱形):强的拥有关系,体现了严格的整体和部分的关系,部分和整体的生命周期相同。 聚合关系(空心菱形):弱的拥有关系,A对象可以包含B…