20050912, 16:54  #1 
Jan 2005
13 Posts 
Convert Binary to BCD code
1. A 16bit register in a computer contains 10110011 11000100. What does its contents represent if it contains
a) a 4digit decimal number in the BCD(binary coded decimal) code, HEre what i have: First i convert binary to decimal and have 46020 in decimal. Then i use the BCD table in the book to convert it from decimal to BCD. Answer= 0100 0110 0000 0001 0000 Please check if i did it wrong. Thanks alot 
20050912, 18:51  #2 
P90 years forever!
Aug 2002
Yeehaw, FL
15261_{8} Posts 
Does anyone still use BCD? Do they still teach this stuff?
My rusty recollections tell me you have an illegal BCD number as input. I suggest googling BCD or "binary coded decimal" and figuring it out. 
20050912, 19:41  #3 
Aug 2002
2^{6}·5 Posts 
I'd say this sounds like homework, but I have no idea what class teaches BCD anymore.

20050912, 22:05  #4 
Oct 2004
tropical Massachusetts
105_{8} Posts 
Heh, the Intel x87 FPU supported loading and storing an 80bit packed decimal format (10byte, 1 sign byte and 18 digits with the remaining 9 bytes), and consequently to this day so does any modern x86 processor. The internal register representation is the standard one though. Well, standard Intel "extendedprecision double".

20050913, 03:41  #5  
"Richard B. Woods"
Aug 2002
Wisconsin USA
17014_{8} Posts 
Quote:
1 (decimal) = 0001 (BCD) 2 (decimal) = 0010 (BCD) 3 (decimal) = 0011 (BCD) 4 (decimal) = 0100 (BCD) 5 (decimal) = 0101 (BCD) 6 (decimal) = 0110 (BCD) 7 (decimal) = 0111 (BCD) 8 (decimal) = 1000 (BCD) 9 (decimal) = 1001 (BCD) The register content 1011 0011 1100 0100 is not itself a 4digit BCD number because neither 1011 nor 1100 is a BCD digit. BCD also interpreted the other 6 bit sequences as plus or minus signs  1011 and 1101 were minus signs, while 1010, 1100, 1110 and 1111 were plus signs. (Yes, two codes for the minus sign and four codes for the plus sign.) (Why not three codes for each sign? (*sigh*) It's a long story.) So, 1011 0011 1100 0100 could be interpreted as BCD "3+4", but that's not a 4digit decimal number.    And yes, packed decimal format is derived from BCD codes  even the plus/minus signs (in IBM's packed decimal, anyway). Last fiddled with by cheesehead on 20050913 at 03:44 

20050916, 21:15  #6 
Jun 2003
153_{10} Posts 
Cheesehead's answer is partly correct but incomplete (as he left out the last 6 "digits"). IBM's hexadecimal BCD code has 16 characters, 0  9 and A  F.
Here are the missing characters: A (decimal) = 1010 (BCD) B (decimal) = 1011 (BCD) C (decimal) = 1100 (BCD) D (decimal) = 1101 (BCD) E (decimal) = 1110 (BCD) F (decimal) = 1111 (BCD) Consequently, 1011 0011 1100 0100 = B 3 C 4 and is considered by IBM mainframe programmers as a 4 digit hexadecimal number which can be added, subtracted, multiplied, etc. like any other number. This is where, I think, the expression "A + 1 = B" came from (e.g. 1010 + 0001 = 1011 or A+1 = B). Last fiddled with by RMAC9.5 on 20050916 at 21:29 
20050916, 22:19  #7  
Cranksta Rap Ayatollah
Jul 2003
641 Posts 
Quote:


20050917, 04:56  #8  
"Richard B. Woods"
Aug 2002
Wisconsin USA
2^{2}·3·641 Posts 
RMAC9.5,
I started programming computers in 1963. At that time (which was before IBM announced its System/360), many mainframes (IBM and others) used word lengths that were a multiple of 3 bits, the number system most commonly used (other than binary and decimal) was octal (base8), and character codes were 6 bits long, not 8. Hexadecimal was not commonly used by programmers (except possibly on a few obscure nonIBM systems) at that time. In its System/360 introductory documents, IBM had to include explanations of the hexadecimal system and how it was related to binary, octal, and decimal, because few programmers were familiar with it. Quote:
As TravisT pointed out, the D in BCD stands for Decimal, not "Hexadecimal". Quote:
In the BinaryCoded Decimal system, the fourbit binary values whose decimal equivalents are 10, 11, 12, 13, 14, and 15 are interpreted as sign (+ or ) codes, not numeric digits. tinhnho quoted "1. A 16bit register in a computer contains 10110011 11000100. What does its contents represent if it contains a) a 4digit decimal number in the BCD(binary coded decimal) code". It is possible that the writer of that question made a mistake  the reference to BCD doesn't really match the register value presented. I've worded my previous responses under the assumption that the writer meant what s/he said, but that might not actually be true.      Also see http://en.wikipedia.org/wiki/Binarycoded_decimal Last fiddled with by cheesehead on 20050917 at 05:09 

20050918, 15:14  #9 
Jun 2003
3^{2}·17 Posts 
Cheesehead, as I was composing my reply a little voice inside my head kept whispering "you are are describing EBCDIC (extended binary coded decimal interchange code) hexadecimal numbers, maybe they are different than BCD decimal numbers"; and "Cheesehead sounds like he might have personal experience (i.e. knows what he is talking about)". Thanks for the history lesson as my IBM mainframe experience dates from 1975 on System 370 machines and I have sometimes wondered what EBCDIC was extended from.

Thread Tools  
Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
convert files from srsieve/srfile into worktodo.txt  Rincewind  PrimeNet  9  20141101 11:47 
How to convert 5495bit binary number to decimal?  Stargate38  Software  12  20120207 21:19 
convert 3d into 2d  nuggetprime  Programming  6  20070922 08:35 
convert to standard ASCII text when possible?  ixfd64  mersennewiki  5  20060406 00:00 
Linux! Convert me!  OmbooHankvald  Linux  8  20050813 23:50 