Storage of float data in memory

Source: Internet
Author: User

Float-type numbers are stored in four bytes in a computer. Compliance with IEEE-754 format standards:

A floating point number consists of three parts:

Symbol. 0 indicates positive, and 1 indicates negative.

The base part uses the binary number to represent the actual value of the floating point number. The base part actually occupies a value of 24 bits, but the maximum bit is always 1. Therefore, the maximum bit is not stored, 23-bit scientific notation in storage.

The index occupies 8-bit binary data, which indicates that the value range is 0-255.

However, the index can be positive or negative. Therefore, IEEE stipulates that the power calculated here must be less than 127, which is the real index. Therefore, float indexes can range from-126 to 128.

Therefore, the format is:
SEEE EEEE EMMM MMMM MMMM MMMM MMMM MMMM

S indicates positive and negative floating point numbers.

The E index is worth the binary data after 127.

M Base

Example:
17.625 storage in memory

First, convert 17.625 to binary: 10001.101.

Integer, divided by 2, until the quotient is 0, the remainder is reversed.
Decimal part, multiply by 2 until the number of digits is 0.

Shift 10001.101 right until there is only one digit before the decimal point: 1.0001101*2 ^ 4 because four digits are moved right.

Base Number: Because the decimal point must be 1, IEEE requires that only the decimal point should be recorded. Therefore, the base number here is 0001101.
Index: Actually 4, 127 must be added (when the transfer is made, minus 127), so it is 131. That is 10000011.
The part of the symbol is positive, so it is 0.

To sum up, the storage format of 17.625 in memory is:

01000001 10001101 00000000 00000000    

Storage of float data in memory

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.