mersenneforum.org Convert Binary to BCD code
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

 2005-09-12, 16:54 #1 tinhnho   Jan 2005 13 Posts 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
 2005-09-12, 18:51 #2 Prime95 P90 years forever!     Aug 2002 Yeehaw, FL 22×5×397 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.
 2005-09-12, 19:41 #3 ColdFury     Aug 2002 26×5 Posts I'd say this sounds like homework, but I have no idea what class teaches BCD anymore.
 2005-09-12, 22:05 #4 trilliwig     Oct 2004 tropical Massachusetts 3×23 Posts 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".
2005-09-13, 03:41   #5

"Richard B. Woods"
Aug 2002
Wisconsin USA

22×3×641 Posts

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

 2005-09-16, 21:15 #6 RMAC9.5     Jun 2003 32×17 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 2005-09-16 at 21:29
2005-09-16, 22:19   #7
Orgasmic Troll
Cranksta Rap Ayatollah

Jul 2003

641 Posts

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?

2005-09-17, 04:56   #8

"Richard B. Woods"
Aug 2002
Wisconsin USA

22·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 (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

 2005-09-18, 15:14 #9 RMAC9.5     Jun 2003 2318 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.

 Similar Threads Thread Thread Starter Forum Replies Last Post Rincewind PrimeNet 9 2014-11-01 11:47 Stargate38 Software 12 2012-02-07 21:19 nuggetprime Programming 6 2007-09-22 08:35 ixfd64 mersennewiki 5 2006-04-06 00:00 OmbooHankvald Linux 8 2005-08-13 23:50

All times are UTC. The time now is 07:34.

Tue Aug 9 07:34:58 UTC 2022 up 33 days, 2:22, 1 user, load averages: 2.15, 1.34, 1.05

Copyright ©2000 - 2022, 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.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎𝜍 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔