- 论坛徽章:
- 0
|
原帖由 mitsuki 于 2007-1-13 16:29 发表
对不起,您给的链接我都打不开
我说的确实不准确,应该是BCD码
我考虑用%d得出的值不换算的话在ASCII表上查不到,所以加了这么一句希望回答能够准确些,没想到还是错了
不过我仍然认为ASCII码的值应该用HEX值,方便查表
谢谢。
From Wikipedia, the free encyclopedia:
In computing and electronic systems, Binary-coded decimal (BCD) is an encoding for decimal numbers in which each digit is represented by its own binary sequence. Its main virtue is that it allows easier conversion to decimal digits for printing or display. Its drawbacks are the complexity of circuits needed to implement mathematical functions and the space wasted in the encoding - 6 wasted patterns per digit. Even though the importance of BCD has diminished, it is still encountered.
In BCD, a digit is usually represented by four bits which, in general, represent the values/digits/characters 0-9. Other combinations are sometimes used for sign or other indications.
To BCD-encode a decimal number using the common encoding, each digit is encoded using the four-bit binary bit pattern for each digit. For example, the number 127 would be:
0001 0010 0111
Since most computers store data in eight-bit bytes, there are two common ways of storing four-bit BCD digits in those bytes:
* each digit is stored in one byte, and the other four bits are then set to all zeros, all ones (as in the EBCDIC code), or to 0011 (as in the ASCII code)
* two digits are stored in each byte.
Unlike pure binary encodings large numbers can easily be displayed by splitting up the nibbles and sending each to a different character with the logic for each display being a simple mapping function. Converting from pure binary to decimal for display is much harder involving integer multiplication or divide operations. The BIOS in many PCs keeps the date and time in BCD format, probably for historical reasons (it avoided the need for binary to ASCII conversion).
附 PDF 格式文档(和 ASCII 等字符编码有关的历史):
----
[ 本帖最后由 langue 于 2007-1-13 16:41 编辑 ] |
|