How to decode an unsigned integer into BCD use VHDL

user1673133 picture user1673133 · Oct 18, 2012 · Viewed 11.8k times · Source

As we can see that,in VHDL ,MOD and REM only can be simulated but can't be synthesized.So how can we get the BCD from an unsigned integer? For example,the integer is 23,how can we get the BCD:0b0010 and 0b0011? Thanks.

Answer

Martin Thompson picture Martin Thompson · Oct 18, 2012

This has been covered elsewhere:

https://electronics.stackexchange.com/questions/22611/binary-to-bcd-converison

  • A lookup table is one option
  • A big case statement is another (Which will get turned into a lookup table)
  • Or an iterative method where you keep subtracting 10 until the remainder is < 10 - the count of subtractions is your tens digit, the remainder is your units digit.