Floating point number ieee 754

WBOY
Release: 2016-08-08 09:21:20
Original
2012 people have browsed it

Convert decimal number to computer stored procedure

Take 9.625 single precision (32 bits) as an example

  1. Convert decimal number to binary representation
    9.625 = 1001.101 = 1 × 2 3 + 0 × 22 + 0 × 21 + 1 × 20 + 1 × 2-1 + 0 × 2-2 + 1 × 2-3

  2. Binary number normalization
    ieee 754 stipulates that binary representation must be in the format ±d.dd…d × βe , (0 ≤ d i < β)
    That is 1001.101 = 1.001 101 * 23

  3. stored to computer
    Single precision total length 32 bits
    1-23 represents the mantissa: Because the binary number after normalization has only one 1 to the left of the decimal point, it can be omitted, so that 23 bits are used to represent 24 bits. That is, the mantissa is 001 101 in 1.001 101
    24-30 represents the exponent: 3 in 1.001 101 * 23
    31 represents the sign: 1 represents a negative number, 0 represents a positive number
    In addition, the exponent bit has 8 bits and can represent values ​​between 0-255. But the exponent may be negative (for example, 0.625 = 0.101 (binary) = 1.01 * 2-1). Therefore, IEEE 754 stipulates that the index is to increase the offset code: the normalized index value + 127. The range of the index becomes -127 - 128. Then the above index becomes 130

    According to the above rules, the binary decimal is stored in the computer as: [0] [1000 0010] [0011 0100 0000 0000 0000 000]

The precision is lost

  1. It can be seen that after normalization The mantissa part of a binary number may be much longer than 23 bits, and the latter part will be lost when the computer stores it. Typical is 0.58.

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the floating point number ieee 754, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!