How to float in memory?

float floating point, 32-bit machine occupies 4 bytes Total 32bit, subscript 0 ~ 31.

31: sign bit, n is 0, a negative number.

30: direction bit. 1 decimal point shift left, right zero.

23 to 29: 7 bit exponent. Index = -1.

0-22: 23 bit mantissa.

Conversion method:

1 partially converted into a binary integer. Integer constant divide by two until the quotient bit 0. Remove the reverse of each remainder.

2 decimal part converted into binary. 2 multiplied by the fractional part of the stop, until the result of the fractional part of the positive sequence taken per bit to 0. quotient.

3 steps one and two get data registration. The results from the first step to the right of the decimal point to the left of the decimal point, second step get. Into scientific notation.

4 stitching. According to the above described filling bit. Mantissa is not enough, the right 0s.

For example: how to write 8.25 12.5 0.25 are stored in memory.

 

8.25 Calculation of storage:

  1. 8 converted into a binary integer part:

    8/2 = I 40

    4/2 = 2 0 I

    2/2 = I 1 0

    1/2 = 0, more than 1 commercial spaces 0 then stop. Get reverse  1000    

     2, the binary fractional part 0.25 transposition:

    0.5 * 2 = 0.25 integer part 0

    2 * 0.5 = 1.0 times the integer part 1 0 is the fractional part is stopped. Get positive sequence 01

  3, in binary:

    1000.01 = 1.00001 * 2 of the third power. Left of the decimal point three.

  4、

    31 :0

    30:  1

    Bit Index: 3-1 = 2 = 0000010

    Mantissa: 0000 1,000,000,000,000,000,000

 

  Final: 0100 0001 0000 0100 0000 0000 0000 0000 = 0x41040000

  If it is more than can be seen only -8.25 highest bit to 1 can be. Final: 1100 0001 0000 0100 0000 0000 0000 0000 = 0xC1040000

  

12.5 of the conversion process:

 1 integer part:

    12/2 = 6 remainder 0

    I 06/2 = 3

    3/2 = I 1 1

    1/2 = 0 I 1

            Get the remainder of 1100 in reverse order

  2 fractional part:

      0.5 1.0 * 2 = an integer from 1

  Get 1

 3: Binary obtained: 1100.1 power = 1.1001 * 2 3

  4: 0 1 0000010 1001 0000000000000000000 = 0x41480000

 

0.25 conversion process

1 is converted to the integer part 0

0.25 fractional part 2 

    0.5 * 2 = 0.25 integer part 0

            0.5 1.0 * 2 = integer part of 1

3 to give 0.01 -2 power 2 = 1.0 *

4 obtained: 0 0 1111101 0000000000000000000000 = 0x3E800000 exponent portion -2-1 = -3 = FD = 11111101 7 away

Guess you like

Origin www.cnblogs.com/lan0725/p/11515584.html