??? 06/07/05 21:01 Read: times Msg Score: +3 +2 Good Answer/Helpful +1 Informative |
#94478 - Just tightening up the terminology Responding to: ???'s previous message |
Juan,
You obviously have the idea, but some of your terminology is a bit loose. As William obviously hasn't got the idea at all, we need to get these things clear: Juan Carlos said:
BCD numbers normally go from 0-9 in bits of 4. BCD = Binary-Coded Decimal; therefore, by definition the digits can only ever go from 0-9. In binary, that's 0000-1010 - so four bits are required for each BCD digit. Thus an eight-bit byte can accomodate two BCD digits - this is sometimes known as packed BCD. If you mask it (AND with a 3) it becomes an ASCII number No, that's wrong. First, we need to be clear that ASCII has nothing to do with numbers. ASCII is a numerical code for representing characters for use in printers, on displays, etc. ASCII is not used for arithmetic! In ASCII, the numerical value thirty-two represents a 'space' character; the numerical value sixty-five represents an uppercase 'A' character; the numerical value ninety-nine represents a lowercase 'c' character; the numerical value fifty represents a character '2'; etc, etc,... We can write those numerical values in various formats, including binary, decimal, and hexadecimal - so the above paragraph can be re-stated as: Decimal 'C' Hexadecimal Binary ASCII-Coded Number Representation Representation Representation Character ----------- -------------- -------------- -------------- ----------- thirty-two 32 0x20 00100000 ' ' sixty-five 65 0x41 01000001 'A' ninety-nine 99 0x63 01100011 'c' fifty 50 0x32 00110010 '2'Now, if you look at the ASCII codes for the digit characters '0' to '9', you should spot a simple relationsip between the numerical value of the ASCII code, and the digit that it represents: ASCII Character Code --------- ----- '0' 0x30 '1' 0x31 '2' 0x32 '3' 0x33 '4' 0x34 '5' 0x35 '6' 0x36 '7' 0x37 '8' 0x38 '9' 0x39 Thus, to convert a numerical value 0-9 into its corresponding ASCII-code value, you simply add (not "AND") 0x30. For multiple digits, you need to apply this conversion to each digit. For a review of the basic principles of radix notation (different number bases), take a look at the excellent MathForum article cited recently by David Mars: http://www.8052.com/forum/read.phtml?id=94177 In fact, while you're there, it'd be well worth looking through the other MathForum articles on the subject... |
Topic | Author | Date |
8051 book question | 01/01/70 00:00 | |
ASCII | 01/01/70 00:00 | |
8051 book question | 01/01/70 00:00 | |
31H | 01/01/70 00:00 | |
Equivalent | 01/01/70 00:00 | |
Just tightening up the terminology | 01/01/70 00:00 | |
Nice Answer![]() | 01/01/70 00:00 |