mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Miscellaneous Math

Reply
 
Thread Tools
Old 2005-09-12, 16:54   #1
tinhnho
 
Jan 2005

13 Posts
Default Convert Binary to BCD code

1. A 16-bit register in a computer contains 10110011 11000100. What does its contents represent if it contains
a) a 4-digit 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
tinhnho is offline   Reply With Quote
Old 2005-09-12, 18:51   #2
Prime95
P90 years forever!
 
Prime95's Avatar
 
Aug 2002
Yeehaw, FL

715510 Posts
Default

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.
Prime95 is offline   Reply With Quote
Old 2005-09-12, 19:41   #3
ColdFury
 
ColdFury's Avatar
 
Aug 2002

26·5 Posts
Default

I'd say this sounds like homework, but I have no idea what class teaches BCD anymore.
ColdFury is offline   Reply With Quote
Old 2005-09-12, 22:05   #4
trilliwig
 
trilliwig's Avatar
 
Oct 2004
tropical Massachusetts

3×23 Posts
Default

Heh, the Intel x87 FPU supported loading and storing an 80-bit packed decimal format (10-byte, 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 "extended-precision double".
trilliwig is offline   Reply With Quote
Old 2005-09-13, 03:41   #5
cheesehead
 
cheesehead's Avatar
 
"Richard B. Woods"
Aug 2002
Wisconsin USA

22·3·641 Posts
Default

Quote:
Originally Posted by tinhnho
1. A 16-bit register in a computer contains 10110011 11000100. What does its contents represent if it contains
a) a 4-digit decimal number in the BCD(binary coded decimal) code
0 (decimal) = 0000 (BCD)
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 4-digit 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 4-digit 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 2005-09-13 at 03:44
cheesehead is offline   Reply With Quote
Old 2005-09-16, 21:15   #6
RMAC9.5
 
RMAC9.5's Avatar
 
Jun 2003

32×17 Posts
Default

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 2005-09-16 at 21:29
RMAC9.5 is offline   Reply With Quote
Old 2005-09-16, 22:19   #7
Orgasmic Troll
Cranksta Rap Ayatollah
 
Orgasmic Troll's Avatar
 
Jul 2003

641 Posts
Default

Quote:
Originally Posted by RMAC9.5
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).
Not disputing what you say, but why would there be binary coded decimal to encode hexadecimal?
Orgasmic Troll is offline   Reply With Quote
Old 2005-09-17, 04:56   #8
cheesehead
 
cheesehead's Avatar
 
"Richard B. Woods"
Aug 2002
Wisconsin USA

22·3·641 Posts
Default

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 (base-8), and character codes were 6 bits long, not 8.

Hexadecimal was not commonly used by programmers (except possibly on a few obscure non-IBM 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:
Originally Posted by RMAC9.5
Cheesehead's answer is partly correct but incomplete (as he left out the last 6 "digits").
No, I left out no digits.

As TravisT pointed out, the D in BCD stands for Decimal, not "Hexadecimal".

Quote:
IBM's hexadecimal BCD code has 16 characters, 0 - 9 and A - F.
Correction: The hexadecimal (base-16) numbering system, which was not invented by IBM, has 16 digits. The hexadecimal digits corresponding to decimal values 10, 11, 12, 13, 14, and 15 are usually written as A, B, C, D, E, and F, respectively.

In the Binary-Coded Decimal system, the four-bit 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 16-bit register in a computer contains 10110011 11000100. What does its contents represent if it contains
a) a 4-digit 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/Binary-coded_decimal

Last fiddled with by cheesehead on 2005-09-17 at 05:09
cheesehead is offline   Reply With Quote
Old 2005-09-18, 15:14   #9
RMAC9.5
 
RMAC9.5's Avatar
 
Jun 2003

100110012 Posts
Default

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.
RMAC9.5 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert files from srsieve/srfile into worktodo.txt Rincewind PrimeNet 9 2014-11-01 11:47
How to convert 5495-bit binary number to decimal? Stargate38 Software 12 2012-02-07 21:19
convert 3d into 2d nuggetprime Programming 6 2007-09-22 08:35
convert to standard ASCII text when possible? ixfd64 mersennewiki 5 2006-04-06 00:00
Linux! Convert me! OmbooHankvald Linux 8 2005-08-13 23:50

All times are UTC. The time now is 11:53.

Thu Sep 24 11:53:58 UTC 2020 up 14 days, 9:04, 0 users, load averages: 2.08, 1.81, 1.66

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.