float vs integer

An integer is 4 bytes on a 32-bit computer. A float is 4 bytes on a 32-bit computer. But a float is required to store more digits than an integer. A float needs to store the oneth's place, the tenth's place, the hundredth's place and so on. That is 10 * 10 * 10 = 1000 and counting extra digits that a float has to store. So how can a float do all this in 4 bytes and yet have all the same positive digits that an integer does?
A float does not store every possible value; there is a gap between a particular value it can represent and the next higher value it can represent.

The count of real numbers between 1.0 and 1.0000000001 is infinity.
An unsigned integer can store any whole number between 0 and 4294967295.

If you try to store 4294967295 as a float, you get something like: 4.2949673 x 109.

A float is just a way of storing a number in scientific notation (base 2) so you can store very big or very small numbers, but less precision.

1 bit to represent the sign
8 bits to represent the exponent (base 2)
23 bits to represent the number

Check this out:
http://www.h-schmidt.net/FloatConverter/IEEE754.html
Last edited on
Topic archived. No new replies allowed.