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.pswp.cn/news/379423.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379423.shtml
英文地址,請注明出處:http://en.pswp.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…