Escolar Documentos
Profissional Documentos
Cultura Documentos
Double-Dabble Binary-to-BCD
Conversion Algorithm
Basic Idea
Y X
1 0 1 1
YX, X is a 4-bit binary number 1 0 1 1
1 0 1 1
Y is a 4-bit binary number (Binary to binary)
1 0 1 1
⇒ can be done by only shifting
1 0 1 1
ex: 1011 1011 (shift left 4 times )
Y is a BCD number (Binary to BCD)
ПX: 0000~1111, U X
РY: 00~15 (two BCD digits, at least 5 bits)) 1 0 1 1
ex: 01000 1000 1 0 1 1
? 1011 Shift left 1 0 1 1
if (U > 4) U U*2+X[3] 1 0 1 1
then U=U+3; 1 0 1 1
Shift left;
Out of range
if (U > 4) then U will be U=U+6;
Binary-to-BCD Converter
Out of range after “shift left” 2
Double-Dabble Binary-to-BCD
Conversion Algorithm
Shift and Add-3 Algorithm (consider 8-bit binary)
1. Shift the binary number left one bit.
2. If 8 shifts have taken place, the BCD number is in
the Hundreds, Tens, and Units column.
3. If the binary value in any of the BCD columns is 5
or greater, add 3 to that value in that BCD column.
4. Go to 1.
Example: 8 bits
Operation Hundreds Tens Units Binary
HEX F F
Start 1 1 1 1 1 1 1 1
Binary-to-BCD Converter 3
Binary-to-BCD Converter 4
Example of converting hex E to BCD
Binary-to-BCD Converter 5
How to implement?
Binary-to-BCD Converter 6
Steps to convert a 6-bit binary number to BCD
Hex 3F
(Cont’d) 6-bit binary input
Add 3 1 0 1 0 1 1 1 1 0 0 0
Shift 4 1 0 1 0 1 1 1
0 C3
Add 3 1 1 0 0 0 1 1
1 1 0 0 0 1 1 1 1 0 0 0 1 1
Shift 5
Shift 6 1 1 0 0 0 1 1
P7 P6 P5 P4 P3 P2 P1 P0
BCD 6 3
P 7 4 3 0
tens units
z 13 10 9 6 5 0 6 3
BCD output
Binary-to-BCD Converter 7
Binary-to-BCD Converter 8
K-Map for S3 A1 A0
A3 A2 A1 A0 S3 S2 S1 S0 A3 A2 00 01 11 10
0 0 0 0 0 0 0 0 00
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 0
0 0 1 1 0 0 1 1 01 1 1 1
0 1 0 0 0 1 0 0
0 1 0 1 1 0 0 0
0 1 1 0 1 0 0 1 11 x x x x
0 1 1 1 1 0 1 0
1 0 0 0 1 0 1 1
1 0 0 1 1 1 0 0 10 1 1 x x
1 0 1 0 x x x x
1 0 1 1 x x x x
1 1 0 0 x x x x S3 = A3+A2A0+A2A1
1 1 0 1 x x x x S2 = A3A0+A2A1’A0’
1 1 1 0 x x x x
1 1 1 1 x x x x S1 = A3A0’+A2’A1+A1A0
S0 = A3A0’+A3’A2’A0+A2A1A0’
Binary-to-BCD Converter 9
exercise
Binary-to-BCD Converter 10