Int int int int int int int int int int int int int int int int int int Forgive me for being a novice.

The next day I went back to the company and studied with my colleagues for almost the whole morning. Finally, I found that the storage structure of mainly int and float is different.

Int is the exact value, and float is the exact value.

Int is 4-byte 32-bit, and float is 4-byte 32-bit, but float has a very different storage structure

   

 

Float contains 1 sign bit, 8 exponent bits, and 23 mantissa bits.

 

A symbol bit representing the positive or negative of a floating point number, 0 for positive and 1 for negative.

 

In the computer world, the carry is binary, and the exponent is 2 to the NTH power. The 8-bit exponent ranges from 0 to 255, while the corresponding actual exponent is -127 to 128. So the actual exponent is equal to the exponent minus 127. In particular, the exponential values of -127 and +128 are reserved for a variety of purposes in IEEE, which will not be described here. If you are interested, you can refer to other materials.

 

The mantissa, it just represents the part of the binary after the decimal point, the one before the decimal point is omitted, the zeros are omitted when all the exponents are zeros and the ones are omitted otherwise.

 

This we can understand, in fact the mantissa to determine the precision of a floating-point number, and number of mainly depends on the size of the index, the mantissa is only 23, and omit the one who is 24, so if the value of the int type within the 2 ^ 24, float can be accurately said, but when more than this number is not necessarily accurate said. The most important thing here is to understand the significant bits of determinacy, which is really important for any basic type conversion. As I explained in this post, both int and float are 32 bits, but the memory structure and storage structure are different. Float can only have 24 bits to determine accuracy, while int is 32 bits. The same can be said for other types.

 

Next, explain the above formula to understand: : :

Before talking about this formula, I would like to mention the difficulty I encountered in the process of understanding, that is, why the value of the 23 mantissa digits is between 1.0 and 2.0. At that time, I could not understand, but later I realized that the 23 mantissa digits are used to represent the decimal place, and the omitted digit is 1, because 0 is meaningless (because if it is 0, A decimal is a decimal no matter how many times it is multiplied. And again, the mantissa of 23 is the decimal place.

 

Post the picture again.

Let’s take an example.

I don’t think I have to go into the sign bits

The exponent place is just like the decimal place, which is 124 (I won’t talk about the algorithm here, look it up on the Internet), and then the last expression is 2 to the 124-127 = 2 to the -3.

And then the mantissa, if you look at the formula, b23 minus I is the digit in the mantissa, b22 when I is 1, the leftmost part, and then times 2 to the minus I. It can also be seen from the above formula that the mantissa part is between 1.0 and 2.0.

 

Multiply the last three parts to get the correct answer.

 

 

PS: This is the first time to write a blog, I may not write well, I hope you forgive me, the above part of the content is reprinted, there may be some mistakes, welcome to point out, thank you.