What is "float"
Float is an abbreviation of Floating Point Number (Floating point number in English).
In most programming languages, this type is used for variables with decimal values, such as 0.1
or 15.0025
.
When a floating point number is stored in memory, 32 bits are used, thus:
Bit 31 = Signal bit. 0 for positive and 1 for negative.
Bits 30 to 23 = Exponent. Think of the number 1.101 x 2^5
, exponent (5) is summed to 127, resulting in number 132. It is the 132 value in binary that goes to memory, in this case. Note that the exponent value never will be negative.
Remaining bits = Mantissa. It is the main part of the number, but it is not stored simply by copying the value of the number in binary. It is first normalized, always leaving the 1
most significant of the binary number to the left of the decimal point. For example, the normalized 1101.101
is 1.101101
, exponent 3.
Related Links: