sp3ctrm5tr

Binary to BCD

Mar 18th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================
  2. Convert 6-bits binary to Binary Coded Decimal
  3. from 0 to 9
  4. =============================================*/
  5.  
  6. module binary2bcd (
  7.     input [5:0] binary,
  8.     output reg [3:0] bcd1, bcd0);
  9.  
  10. always@(binary)
  11.     begin
  12.     bcd0 = binary%10;                                           // Calculation for the first digit
  13.     bcd1 = ((binary - binary%10)/10)%10;    // Calculation for the second digit
  14.     end
  15.    
  16. endmodule
Advertisement
Add Comment
Please, Sign In to add comment