───✱*.。:。✱*.:。✧*.。✰*.:。✧*.。:。*.。✱ ───

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 𝑠×(2𝑒)×𝑚.
    • 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 for 133.
    • The actual exponent would be 1331276

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 to 10101001
    • With the implicit leading 1: 1.010100121+14+116+164+15126815121.33

Final Decimal Value

  • The final decimal value is the mantissa multiplied by the exponent.
  • In our case, 681512×26681×645124358451285.03125

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 be 0

Mantissa

  • We need to split 13.625 into the whole and fractional parts: 13.6251101.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 3 places, the exponent would be 3.
  • Since the bias is 127, the actual exponent value would be 130 (100000102)

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)
  • 13.6250 10000010 10110100000000000000000

───✱*.。:。✱*.:。✧*.。✰*.:。✧*.。:。*.。✱ ───