The float type number is stored in a computer with 4 bytes. Follow the IEEE-754 format standard:
A floating-point number consists of 2 parts: base m and index E
The base section uses a binary number to represent the actual value of this floating-point
The exponent portion occupies a binary number of 8bit and can represent a range of 0-255
However, the index can be negative, so the IEEE stipulates that the sub-square must be subtracted from 127 to be the true exponent.
Therefore, the float type index can be from 126 to 128
The base part is actually a value of 24bit, but the highest level is always 1, so the top bit is omitted from storage, and the storage occupies 23bit
Scientific counting method.
Format:
Seee eeee emmm MMMM MMMM MMMM MMMM MMMM
s indicates floating-point number plus or minus
e-index plus 127 worth of binary data
M base
Example:
17.625 in-memory storage
The first thing to do is convert 17.625 into binary: 10001.101
The integer part, divided by 2, until the quotient is 0, and the remainder is reversed.
The decimal part is multiplied by 2 until the multiply bit 0 and the rounding order is taken.
Move 10001.101 to the right until the decimal point is only 1 digits away:
1.0001101 * 2^4 because right moved four bit
This time, our base and index are out.
Base: Because it must be 1 before the decimal point, the IEEE stipulates that only the decimal point will be recorded. So, the base here is: 0001101
Index: Actual 4, must be added 127 (when the turn out, minus 127), so 131. Which means 10000011.
The symbol part is an integer, so it's 0.
In summary, the 17.625 storage format in memory is:
01000001 10001101 00000000 00000000
How the float data is stored in memory