Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Converting a number from base 10 to 32-bit floating point integer:
- Let's use an example number.
- 1701.125
- The structure of a floating point number is this:
- 0 1 .... 8 9 ... 31
- x xxxxxxxx xxxxxxxx
- ^ ^ ^
- Sign Exponential Fractional
- Sign: Either a 0 or 1. 0 = positive, 1 = negative
- We'll cover over exponential and fractional when we get there.
- ================================================================
- 1) Convert DEC to binary format.
- ================================================================
- 1001.125 is 11010100101.001 in binary format.
- ================================================================
- 2) Move the decimal spot so that it's in scientific notation.
- ================================================================
- This process will help find the exponential bit, which is going to be
- an 8-bit binary number.
- So in the case of...
- 11010100101.001
- The decimal point will move 10 times, so that it'll be:
- 1.1010100101001 * 2^10
- You must remember how much you've moved it by, it plays a role next.
- ================================================================
- 3) Add that number to 127, then take the binary form of it.
- ================================================================
- So 10 + 127 = 137.
- 137 will now need to be converted to binary form, which is:
- 10001001
- You have now found the exponential bits. This goes inside slots 1-8
- in the floating point number.
- ================================================================
- 4) All the numbers have after the decimal belong in the fractional.
- ================================================================
- Our binary value is...
- 1.1010100101001 * 2^10
- So 1010100101001 goes inside the fractional significand, starting from
- bit 9.
- After the number finishes, the rest of the bits will be 0 until you reach
- bit 32.
- So in this case, the fractional bit will contain:
- 10101001010010000000000
- ================================================================
- 5) Put them together...
- ================================================================
- Sign: 0
- Exponential: 10001001
- Fractional: 10101001010010000000000
- Final 32-bit floating point:
- 01000100110101001010010000000000
- In Hex format:
- 44D4A400
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement