In order to compare results, all of the numbers were checked with an online IEEE 754 float converter. ![]() We can this program by breaking it into functions that allow us to run different values through it. The sign bit was set at the beginning of the program when we determined whether to flip the bits of the LHS register from 2’s complement. In the following example the loop runs through the whole set of iterations without any break to make it synthesizable. This tells us the number of shifts that need to be performed in order to reconstruct the floating-point number from IEEE format. Because you used logic in your example, I assumed that system verilog syntax is ok here. The exponent value comes from the length that the most-significant 1-bit is in. This gives us a complete mantissa value for the result. If there are, we should round the last bit of the mantissa to 1. In computing and electronic systems, a binary-coded decimal (BCD) is a digital encoding method for decimal numbers in which each digit is represented by its own binary sequence. If the RHS value gets shifted too far to the right and we lose precision, we need to check if there are any 1-bits to the right of where the value gets cut off. The Verilog code below illustrates converting a 4-digit BCD number to it’s binary equivalent. The BCD to Binary Converter is used to convert a BCD (Binary-coded decimal) to a binary (Base-2) number. Since we stored our fraction starting in the MSB, we take the value from that register, shift it to the right however many binary digits the left value takes up, and OR the mantissa LHS value with the RHS fraction. The RHS fractional value must be combined with the LHS value already stored in the result register. Then we apply the AND operation to the mask and the LHS value, and shift the result into the most significant bit for the mantissa value (position 22). To get the mantissa value, if there is a value in the left-hand argument, we find the most significant 1-bit and create a bit mask that is the length of the value excluding the most significant 1-bit. Knowing this value allows us to treat the integer value like a decimal so that we can use a doubling technique to find its binary fractional approximation. We do this by finding a power of 10 that is greater than the RHS argument. The RHS is passed in as an integer, so we need to convert it to a binary fraction. We convert the left-hand argument to a positive binary number even if it was stored as a negative (2’s compliment). ![]() The following approach was used to generate a floating point number: The following article discusses exactly what a floating point number is. ![]() A simple routine in Verilog HDL that converts integers into IEEE 754 Floating Point format.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |