Storage of floating point numbers in computers

Source: Internet
Author: User

Float F = 1.3f;
How is it stored on 32 computers?
We know that a float occupies 4 bytes, that is, 32 bits. And the Intel processor is small-end. The low position is in high byte, and the high position is in low byte. For discussion convenience, we first find the 32-bit representation of the floating point number corresponding to 1.3, and then change the byte order.

First, convert 1.3 to binary: the integer is the normal method. For decimal places, it is * 2. If it is greater than 1, it is 1, and less than 1 is. 010011001100110011001100110011 ...... It is omitted later.

Second, convert it to the "scientific notation" with 2 as the base: 1.010011001100110011001100110011*2 ^ 0
Where 0 is the index, and that long string is the base number.
With these preparations, we can perform the following operations:
(1) In the 32bit, the first digit is the sign bit 0, indicating a positive number, and 1 indicates a negative number. Here we are 0.
(2) the next 8 digits represent the index: the actual index + 127 is used. Here we use 0 + 127 = 127 = 01111111
(3) If the remaining 23 digits represent the ending number, we can just copy 01001100110011001100110.
The merging is:
001111111010011001100110 01100110
As mentioned above, our computers are generally small-end computers, so the actual storage order is:

011001100110011010100110 
00111111

We will use this knowledge in future studies. Record it here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.