b_book1.gif (162 bytes) Data - Coding systems
BCD | Binary vs BCD | Numeric data | Answers

Encoding numeric data - bcd

  •  As discussed previously, errors occur when converting decimal numbers to binary.
  • In many financial computations, these calculation errors could result in substantial monetary loss.
  • Hence, Binary Coded Decimals (also known as Packed Decimal) were introduced.
  • Here, a code is used to store the actual binary digits.
  • For example, $25. 22. As a floating Point Number the fraction 25.22 would be an approximation

Binary Coded Decimal (BCD)

To give accuracy in computation for applications the solution is BCD -- Binary Coded Decimal where each DIGIT is represented by 4 bits.
So 2 digits can be stored in each byte. Only digits from 0 -9 are used, so the binary codes from 1010 to 1111 are not valid digits.

0
1
2
3
4
0000
0001
0010
0011
0100
5
6
7
8
9
0101
0110
0111
1000
1001

For example:

437(base 10) = 0100 0011 0111
= 110110101
BCD
Binary

Exercise 1 : Give Bit patterns for the following in BCD and Binary numbers
                   a) 32, b) 900, c) 4, d) 11

Binary/BCD differences

Add 27 and 35 Binary BCD
1. Entering 27 and 35 full conversion to binary (slow) Conversion to BCD format (fast)
2. Adding the numbers fast binary addition complex addition algorithm
3. Produce the result full conversion to decimal (slow) fast conversion of BCD format

Answers

Answers 1 : Bit patterns for the following in BCD and Binary

a) 32 = 0011 0010bcd, (i.e. 3 (0011) 2 (0010))
= 100000 base 2
b) 900 = 1001 0000 0000bcd,
= 1110000100 base 2
c) 4 = 0100bcd,
= 0100 base 2
d) 11 = 0001 0001bcd, ( i.e. 1 (0001) 1 (0001))
= 1011 base 2

[Rev 18/03/99] 25/4/97 © 1997-99 V/2-Com (Verhaart), P O Box 8415, Havelock North, New Zealand.