float are stored in the computer

1, float type in a digital computer by 4 bytes (32-bit) is stored.

Follows the IEEE-754 standard format:
a floating-point number consists of three parts: the sign bit s (1 bit) and the exponent e (8 bits), base-m (23-bit)

 

2、格式
SEEE EEEE EMMM MMMM MMMM MMMM MMMM MMMM

S: sign bit
E: index, index plus decimal binary data worth 127
M: base number

 

3, the sign bit

It refers to a base number of sign, either positive or negative.

 

4, index

8bit binary number occupies can be expressed as a range of values ​​0-255.

But the index can be positive or negative, so, IEEE provisions, calculated here is the real power must be reduced by 127 index.

Therefore, float type from index -126 to 128

 

5, base number

The actual value is a 24bit occupied, but the most significant bit is always 1, thus, eliminating the need for the highest level is not stored in the storage accounts for 23bit
scientific notation.

 

6, for example:
17.625 stored in memory

We must first be converted into a binary 17.625: 10001.101

10001.101 in the right until the front left of the decimal point one:
1.0001101 * 2 ^ 4 as right movement of the four

Base number: since the front of the decimal point must be 1, so that only a predetermined recording IEEE like after the decimal point. So, here's base number is: 0001101
Index: 4 actual, must be added 127 (roll-out time, minus 127), it was 131. That is 10000011
symbol: integer, 0


In summary, 17.625 in memory storage format is:
0,100,000,110,001,101 00000000 00000000

Guess you like

Origin www.cnblogs.com/limaodeng/p/11568539.html