Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Single precision floating point binary calculation process
- Exercise: Convert 469.357 to a raw binary floating point representation
- # Sign
- 0 (Because 0 if positive, 1 if negative)
- ==> Sign = 0
- # Exponent and Mantissa
- ### Convert the whole part into binary (WholeBinary)
- 469 / 2 = 234 1 (Because 469 / 2 has a reminder (atlikums) = 1)
- 234 / 2 = 117 0
- 117 / 2 = 58 1
- 58 / 2 = 29. 0
- 29 / 2 = 14. 1
- 14 / 2 = 7. 0
- 7 / 2 = 3. 1
- 3 / 2 = 1 1
- 1 / 2 = 0 1
- WholeBinary = 111010101 (Read from bottom up)
- ### Convert the fraction into binary (FractionBinary)
- 0.357 * 2 = 0.714 0 (If you multiply by 2 and the result is larger than 1, then write down 1, otherwise 0)
- 0.714 * 2 = 1.428 1
- 0.428 * 2 = 0.856 0 (Once you go over one in the results, remove the one, e.g. 1.428 -> 0.428)
- 0.856 * 2 = 1.712 1
- …..
- (Continue till you’re out of space or smth - enough to later fill all 32 bits including mantissa and sign)
- FractionBinary = 010110110110010
- ### Convert the binary number into a normalized binary scientific notation (e.g. 1.0000010101 * 2^12)
- NumberBinary = 111010101 . 010110110110010 (WholeBinary . FractionBinary)
- NumberBinaryScientific = 1 . 11010101010110110110010 * 2 ^ 8 (NumberBinary in scientific notation)
- ==> Mantissa = 11010101010110110110010 (NumberBinaryScientific without the leading zero)
- ==> Exponent = 8 + 127 = 135 = 10000111 (NumberBinaryScientific exponent + 127 in binary)
- # All together
- Floating binary format = Sign Exponent Mantissa
- ==> Full Single-precision floating binary = 0 10000111 11010101 010110110110010
- ==>Online converter result = 0 10000111 11010101 010110110110010
- Conclusion - you did it correctly!
- ### Sidenote
- Online converter here = https://www.exploringbinary.com/floating-point-converter/
- Use "Single precision" and "Raw binary format"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement