![]() ![]() This approach basically is a way to overflow any values greater or equal to 10 in a digit into the next one without too much hardware. Essentially the approach is to scan through the binary representation, then any time you see a number which is 5 or higher in each group of 4 bits, you add 3 to it. The simplest way of converting from binary to BCD is an algorithm called "Shift-Add-3" or "Double-Dabble" (both names for the same thing). This is an ideal format for outputting to 7-segment displays, screens, in fact anything that needs a decimal number to be displayed. In BCD each digit is 4 bits, but those 4 bits are only used to represent the numbers 0-9 (hence the decimal bit). ![]() The problem you are having is quite a common one - how to convert a binary number to something called "Binary Coded Decimal" (BCD). I want it so that if I pass in binary 10, ( 8'b00001010), then HEX1 HEX0 should be 1 0, not 0 A (as hex works) The only problem is that after 9, the values will become in hex letters. To output on HEX0 and HEX1, I can do something like this: hex_decoder h0(.hex_digit(value), HEX0) Suppose I have the module as follows: module hex_decoder(hex_digit, segments) Suppose I have an 8 bit value, say 8'b00000001 (1)
0 Comments
Leave a Reply. |