Home ] Up ] Adders ] Subtractors ] Multipliers ] Division ] [ Conversions ]
Conversions

Up ]

Return to DIG #12

Binary to Bcd - Bcd to Binary

bullet

 Please check this site: http://www.doulos.com/knowhow/vhdl_designers_guide/models/binary_bcd/

bullet

 The ideas of Bin to Bcd conversions can be found at this "old" document:  XAPP029
 

  Its possible to convert a Binary to Bcd values (and the other way around), with a "slightly modified" 4-bit shift register  (one for each Bcd-number).
 
 

 

 

 

         After the shift                    Before the shift

Bcdx+1  (next bit)    Bcdx   <=  Bcdx+1   (next bit)  Bcdx
  
0             (0)            0      <=       0              (0)          0       hence    0 <= 0 * 2
   0             (0)           
2      <=       0              (0)          1       hence    2 <= 1 * 2
   0             (0)           
4      <=       0              (0)          2       hence    4 <= 2 * 2 
   0             (1)           
6      <=       0              (0)          3       hence    6 <= 3 * 2 
   0             (1)           
8      <=       0              (0)          4       hence    8 <= 4 * 2 
  
1             (0)            0      <=       0              (1)          5       hence  10 <= 5 * 2 
  
1             (0)            2      <=       0              (1)          6       hence  12 <= 6 * 2 
  
1             (0)            4      <=       0              (1)          7       hence  14 <= 7 * 2 
  
1             (1)            6      <=       0              (1)          8       hence  16 <= 8 * 2
  
1             (1)            8      <=       0              (1)          9       hence  18 <= 9 * 2 

 

 

Layout for a x-bit binary to 5 digit Bcd converter.

 
  The principle in a Binary to Bcd conversion

0000 -0- 0000 -0- 0000 -0- 0000 -0- 0000 <= 11101110
0000 -0- 0000 -0- 0000 -0- 0000 -0- 0001 <= 11011100
0000 -0- 0000 -0- 0000 -0- 0000 -0- 0011 <= 10111000
0000 -0- 0000 -0- 0000 -0- 0000 -1- 0111 <= 01110000

0000 -0- 0000 -0- 0000 -0- 0001 -0- 0100 <= 11100000
0000 -0- 0000 -0- 0000 -0- 0010 -1- 1001 <= 11000000
0000 -0- 0000 -0- 0000 -1- 0101 -1- 1001 <= 10000000
0000 -0- 0000 -0- 0001 -0- 0001 -1- 1001 <= 00000000
0000 -0- 0000 -0- 0010 -0- 0011 -1- 1000 <= 00000000

0          0            2             3             8                    

111011102 = 128+64+32  +8+4+2 = 255 -16-1 = 238

   

A possible solution to the "modified shift register" for Binary to Bcd and vice versa.