For faster navigation, this Iframe is preloading the Wikiwand page for 二進碼十進數.

二進碼十進數

二進碼十進數(英語:Binary-Coded Decimal,簡稱BCD中国大陆BCD码二-十进制编码)是一種十进制數字編碼的形式。在這種編碼下,每个十进制数字用一串单独的二进制位元來儲存與表示。常见的有以4位元表示1个十进制数字,称为压缩的BCD码(compressed or packed);或者以8位元表示1个十进制数字,称为未压缩的BCD码(uncompressed or zoned)。

這種編碼技术,最常用於會計系統的設計裡,因為會計制度經常需要對很長的數字做準確的計算。相對於一般的浮點式記數法,採用BCD碼,既可保存數值的精確度,又可使電腦免除作浮點運算所耗費的時間。此外,對於其他需要高精確度的計算,BCD編碼亦很常用。

BCD码的主要优点是在机器格式与人可读的格式之间转换容易,以及十进制数值的高精度表示。BCD码的主要缺点是增加了实现算术运算的电路的复杂度,以及存储效率低。

常用BCD編碼方式

[编辑]

對應不同需求,各人亦開發了不同的編碼方法,以適應不同的需求。這些編碼,大致可以分成有權碼無權碼兩種:

  1. 有权码,如:8421(最常用)、2421、5421
  2. 无权码,如:餘3码、格雷码

8421码

[编辑]

8421码又称为BCD码,是十进制代码中最常用的一种。[1]在这种编码方式中,每一位二值代码的“1”都代表一个固定数值。将每位“1”所代表的十进制数加起来就可以得到它所代表的十进制数码。因为代码中从左至右看每一位“1”分别代表数字“8”“4”“2”“1”,故得名8421码。其中每一位“1”代表的十进制数称为这一位的权。因为每位的权都是固定不变的,所以8421码是恒权码。

余3码

[编辑]

余3码是由8421码加上0011形成的一种无权码,由于它的每个字符编码比相应8421码多3,故称余3码。例如,十进制字符5的余3码等于5的8421码0101加上0011,即为1000。同样,余3码中也有6种状态0000,0001,0010,1101,1110和1111是不允许出现的。 余3码也是一种对9的自补代码,因而可给运算带来方便。其次,在将两个余3码表示的十进制数相加时,能正确产生进位信号,但对“和”必须修正。修正的方法是:如果有进位,则结果加3;如果无进位,则结果减3。 余3码与十进制之间的转换也是按位进行的,值得注意的是每位十进制数的编码都应余3。

2421码

[编辑]

2421码是一种有权码,权值由高到低分别为2、4、2、1,特点是大于等于5的4位二进制数中最高位为1,小于5的最高位为0。如5的2421码表示为1011而不是0101。

比較

[编辑]

以下為三種常見的BCD編碼的比較。

十進數 8421-BCD碼 餘3-BCD碼 2421-A碼
(M10 D C B A C3 C2 C1 C0 a3 a2 a1 a0
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

外部連結

[编辑]

BCD-Code页面存档备份,存于互联网档案馆

参考文献

[编辑]
  1. ^ Evans, David Silvester. Chapter Four: Ancillary Equipment: Output-drive and parity-check relays for digitizers. Digital Data: Their derivation and reduction for analysis and process control 1. London, UK: Hilger & Watts Ltd / Interscience Publishers. 1961-03: 46–64 [56–57] [2020-05-24].  (8+82 pages) (NB. The 4-bit 8421 BCD code with an extra parity bit applied as least significant bit to achieve odd parity of the resulting 5-bit code is also known as Ferranti code.)
{{bottomLinkPreText}} {{bottomLinkText}}
二進碼十進數
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?