The conversion formula is probably like this.įormula editing is done with the Markdown editor Typora. So the conversion between binary numbers and decimal numbers is multiplying by 2, that is, shifting one bit to the left. Why use the left shift method? This is because of the bit weight relationship between binary numbers and decimal numbers.
(4’b0011 is also 4’b0110 after shifting to the left, and the number of bits of the BCD code is corrected the same before and after shifting). Here are the two methods of adding 6 after shifting and adding 3 before shifting. There is no BCD code 4'b1010, so add 6 and carry to the higher position.
If this is considered to be greater than 4, such as 5, 4'b0101, it will become 4'b1010 after the next shift. Why is it greater than four here? The BCD code is a four-digit binary number that represents one bit of a decimal number. During the process, if the shifted value is greater than 4, add 3 to the changed value before shifting.
Perform a left shift as shown in the following table. Taking an eight-bit binary as an example, the value can be up to three decimal digits. In simple terms, the shift plus 3 algorithm is, how many binary bits there are, and how many shifts are performed. A 4-digit binary number is used to represent the 10 digits of 0-9 in a 1-digit decimal number. But this will consume too much resources, and the conversion from binary to BCD code can be realized by using the shift plus 3 algorithm.īCD code (Binary-Coded Decimal) is also called binary-coded decimal or binary-coded decimal code. For Verilog, its standard is to support division and remainder operations, and the synthesizer will also have IP to perform division operations. For a two-digit value, divide by 10 to get the value of the ten digit, and take the remainder of 10 to get the value of the one digit. In digital circuits, data is stored in binary form. In project design, it is often necessary to display some values, such as temperature, humidity, time, and so on.