Binary Coded Decimal (BCD) and Packed Decimal Format Numbers

preview_player
Показать описание
Working directly with numbers in base 2 or binary has some drawbacks for computers. Namely there is a loss of precision when converting fractions between bases. Binary Coded Decimal or BCD for short is a method of encoding decimal numbers within for binary bits or a nibble. Packed Decimal format is a method to manage decimal placement and sign of the value stored.

If you have an 8 bit (1 byte) store location can store 2 BCD digits with a range of 0-99.
Example: 42 in BCD is: 0100 0010 (a 4 and a 2)
Remember that 42 represented in base 2 is 101010.
Рекомендации по теме
Комментарии
Автор

To help you practice, create a simple (1 digit x 1digit) multiplication problem like the 6x7 one done is in the video.  Show each step and how the CPU must deal with re-encoding when necessary (0111 x 0111 = 1110 + 0110 (re-encode) = 0001 0100)

I will show the 6x7 done in the video here.
Remember the adder is going to add each value then determine if it needs to re-encode by adding 6 (0110) in at each step.

Step 1: Add the first 2 7's.
0111
+0111

1110 <- 14! re-encode to BCD!
+0110

10100 or 0001 0100 (1, 4)

0001 0100
+. 0111 <-- add 3rd 7

0001 1011 < last digit 13! (re-encode)
+. 0110

0010 0001 <- 2 1 ! good.
+ 0111 <-- add 4th 7

0010 1000 <- 2 8 ! good!
+. 0111 <-- add 5th 7

00101111 <-- last digit 15! (re-encode)
+. 0110

00110101 <-- 3 5 ! good.
+. 0111 <-- add 6th and final 7

00111100 <-- last digit 12, (re-encode)
+. 0110

01000010. <-- 4 2 ! (answer!)

CodingCoach
Автор

8x3:
1000 ---> First 8
+ 1000 ---> Second 8

10000 ---> 16 in BCD
+1000 ---> Third 8

00011000 ----> 24 in BCD

jasonhodge