───✱*.。:。✱*.:。✧*.。✰*.:。✧*.。:。*.。✱ ───
IEEE 754 → Decimal
- An IEEE 754 floating point number consists of 3 parts, the sign, exponent and the mantissa.
- The decimal number can be constructed with the equation .
- Where is the sign, is the exponent, and is the mantissa.
- Consider the binary number
0 10000101 01010100100000000000000
Sign Bit
- The sign bit is the first part of an IEEE 754 floating point number.
- For instance, with a binary number of the example would be
0
, which would mean it’s a positive number.
Exponent
- The exponent indicates how big the floating point number will be.
- IEEE 754 uses a bias of 127, so you subtract your number from that.
- The bias is so the exponent can also support negative numbers
- In this case,
10000101
is binary for133
.- The actual exponent would be
Mantissa (Significand)
- The mantissa is what stores the actual ‘digits’ of the decimal number.
- The mantissa has an implicit leading 1
- In this case, it’s
1010100100000000000000
, which can be shorted to10101001
- With the implicit leading 1:
Final Decimal Value
- The final decimal value is the mantissa multiplied by the exponent.
- In our case,
Decimal → IEEE 754
- To convert a decimal to IEEE 754, it’s pretty straightforward—you just need the 3 parts.
- For instance, consider a decimal number
13.625
Sign Bit
- Since
13.625
is positive, the sign bit would be0
Mantissa
- We need to split
13.625
into the whole and fractional parts:13.625
→1101.101
- Once we have the two parts, we need to normalize it by the decimal point to the left.
- Each position you shift it is one power towards the exponent
- The normalized mantissa (with leading 1) would be
1.101101
Exponent
- Since we had to normalize the decimal point by moving it places, the exponent would be .
- Since the bias is , the actual exponent value would be ()
Final IEEE 754
- Once you have these three parts, you can combine them to get the final float.
- Sign →
0
- Exponent →
10000010
- Mantissa →
10110100000000000000000
(no leading 1)
- Sign →
13.625
→0 10000010 10110100000000000000000
───✱*.。:。✱*.:。✧*.。✰*.:。✧*.。:。*.。✱ ───