IEEE floating point representation

Source: Internet
Author: User

Directory:
1. Introduction
2. Float specifications
3. Conversion example

Content:

1. Introduction
Currently, the known C/C ++ compilers perform computation based on the IEEE floating point representation developed by the IEEE (International Association of electronic and electrical engineering engineers.
This structure is a scientific representation expressed by symbols (+ or-), exponent, and ending number. The base number is determined as 2.
Therefore, in the IEEE floating point representation, a floating point number adds a symbol to the exponential power of the ending number multiplied by 2.

2. Float specifications
Float 32-bit, 4-byte
From the highest to the lowest Bit are 31st, 30, 29 ,...... 0 bits, then:
31 is the symbol bit. 1 indicates that the number is negative, and 0 indicates that the number is negative.
30-23 digits. A total of 8 digits are exponential digits.
22-0 digits. A total of 23 digits are the ending digits.

3. Conversion example
Converts a float floating point number 12345.0f to a binary value based on the IEEE floating point number representation.
When processing floating point numbers without decimals, the integer is directly converted into a binary representation: 1 11100010 01000000 can also be expressed as: 11110001001000000.0
Then, move the decimal point to the left, and move it to only one digit from the highest digit: 1.11100010010000000 shifted to 16 digits in total,
Therefore, the original number is equal to 1.11100010010000000*(2 ^ 16 ). We can see that the ending number is 1.11100010010000000, and the index is 16.

Obviously, the highest bit is always 1, so this 1 does not need to be retained.
In this way, the binary number of the tail is changed to: 11100010010000000.
Finally, add 0 after the ending number until 23 digits: 11100010010000000000000

A total of eight digits can represent an unsigned integer ranging from 0 to 255, or an unsigned integer ranging from-128 to 127.
Because the exponent can be negative, 127 is added first to convert the decimal integer into binary.
Here, after we add 127 to 16, it becomes 143. The binary value is 10001111.
The number of 12345.0f is positive, so the symbol bit is 0, so we can combine it according to the preceding format:
0 10001111 11100010010000000000000
Symbol index ending number
That is, 01000111 11110001 00100000 00000000

 

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.