Floating point representation
Posted: Wed Oct 12, 2011 11:58 pm
I've been reading a TON regarding this topic, yet im still very confused on the matter. How are floating point numbers represented? Everything i've read has basically told me the same exact thing, and has never showed an example that i was able to understand! I feel as though i've read so much differently stated information, that nothing make sense/is correct anymore. This my current understanding, please correct what isnt right.
The MSB (2^31 for 32bit system) is responsible for the negative/positive sign like it is with normal signed integers. The next 8 bits are a biased exponent (this is what i understand to be val - 127? With a range of 1-254 (0/255 are for special numbers)). The remaining bits, the mantissa/significand, are for the fraction data.
The thing that im seriously having problems with is CONVERTING. Im trying to make sense of a floating number, but i just get data that doesnt remotely make sense to me. These are my issues with converting (i know some of the stuff is going to sound stupid- i dont mind appearing stupid as long as i learn):
The MSB (2^31 for 32bit system) is responsible for the negative/positive sign like it is with normal signed integers. The next 8 bits are a biased exponent (this is what i understand to be val - 127? With a range of 1-254 (0/255 are for special numbers)). The remaining bits, the mantissa/significand, are for the fraction data.
The thing that im seriously having problems with is CONVERTING. Im trying to make sense of a floating number, but i just get data that doesnt remotely make sense to me. These are my issues with converting (i know some of the stuff is going to sound stupid- i dont mind appearing stupid as long as i learn):
- Converting FROM float:
- Mantissa * 10^130 will never equal our desired value "13.37" no matter where we put the decimal (or radix point). This is seriously confusing!
Code: Select all
Original number: 13.37 Binary number: 01000001010101011110101110000101 MSB: 0. Biased Exponent: 130 (10000010). Mantissa: 5630853 (10101011110101110000101).
- My main issue with converting TO a float value comes from lack of information + sleep deprivation. The first bit of information is where does the decimal point start? I've seen scientific notation denoted tons of different ways, so which one is correct here? If i store 1337 inside of the mantissa where does the decimal go? (Is it safe to assume it goes 1.337? I've seen it go 0.1337). Its important to know where the decimal goes, other wise it could be off when multiplying :'(.
- The biased exponent is confusing. Assuming the exponent is implicitly placed after the one (1.337) i want to multiply it by 10^1. This is normally would be straight forward, except we have the bias to account for, which makes me unsure HOW i should store the value 1. Do i store it as 0b1 (0b1 - 127 = -126) or do i store it as 0b10000000 (128 - 127 = 1). I might be over thinking this part. I believe it to be the first, but it feels so unnatural and confusing (especially when READING).