Binary to bcd verilog5/28/2023 ![]() If ( hundreds >= 5 ) hundreds = hundreds + 3 if ( tens >= 5 ) tens = tens + 3 if ( ones >= 5 ) ones = ones + 3 //shift left Module binaryToBCD ( input binary, output reg hundreds, output reg tens, output reg ones, output reg overflowFlag ) integer i always ( binary ) begin hundreds = 4'b0000 tens = 4'b0000 ones = 4'b0000 overflowFlag = 0 if ( binary > 999 ) begin overflowFlag = 1 end else begin for ( i = 9 i >= 0 i = i - 1 ) begin //if >=5 add 3 If no more shifts remain in the binary number – done.The algorithm for converting binary to BCD is the following: This module has an input of a 10 bit binary number and outputs 3 BCD digits that are 4 bits each. A Binary to BCD converter module, a BCD multiplication module, and a main module for connecting the two others together. Output is a 6 digit BCD number (4 bits for each digit).Input is two 3 digit binary numbers (10 bits each).
0 Comments
Leave a Reply. |