Floating point numbers represent viewing
🔬 IEEE 754 bit pattern parsing
💡 Instructions for use
- Three inputs are supported: decimal number (0.1), hexadecimal (0x3FB999999999999A) and binary bit string of corresponding length.
- Single precision and double precision check length respectively: single precision hexadecimal 8 bits, binary 32 bits; double precision hexadecimal 16 bits, binary 64 bits.
- There is a special case when the exponent bits are all 0s or all 1s: zero or a denormalized number, infinity or a non-numeric NaN, respectively, and are clearly marked in the result area.
- The standardized form is given in one line as "sign × mantissa × 2 raised to the power of the exponent" to facilitate comparison with the notation in the textbook.
Floating point representation viewing turns abstract numbers into bit strings that can be checked bit by bit: it is clear at a glance which bit is the sign, which bit is the exponent, and the rest is the mantissa.
Why do we need to look at bit representation?
Many floating-point problems can only be explained by bit patterns: why two seemingly equal numbers are not equal, why the end of a large integer has changed, and why the serialized bytes are different from expected. Looking at each position one by one can pin these problems down to specific positions and avoid troubleshooting based on guesswork.
The order in which bit strings are read
- Look at the highest position first to determine whether it is positive or negative.
- Then read the exponent segment to see if it is too large, too small, or all 0 or all 1, and judge the order of magnitude and special value accordingly.
- Finally, look at the mantissa section, which determines the significant digits; non-zero digits at the end usually indicate traces of rounding.
The result area displays three segments separately with offsets attached. Read them in this order to make a complete judgment on the values.
It is easiest to understand by splitting the bit pattern into three parts: the sign bit determines the sign, the exponent determines the magnitude, and the mantissa determines the significant digits. The three parts perform their own duties, and changing any one of them will result in completely different values.
When observing special numerical values, the bit pattern is more intuitive than the decimal system: the exponent code is all one, which means infinity or non-number, and the exponent code is all zero, which means zero or denormalized number. These rules are not visible in decimal form.
Copy the bit pattern into three sections, so it is not easy to misread the position during troubleshooting.
If there are a large number of non-zero bits at the end of the mantissa, it usually means that the decimal fraction cannot be accurately represented in binary.
📖 Glossary
- IEEE 754
- An international standard that defines how floating-point numbers are stored and operated on in computers using binary systems. It specifies the bit layout for single-precision and double-precision.
- sign bit
- The highest bit, 0 for positive numbers and 1 for negative numbers; it determines the sign rather than the size.
- Exponent bit
- A section immediately following the sign bit, 8 bits in single precision and 11 bits in double precision, used to represent powers of 2.
- offset
- A fixed value added when the exponent is stored, 127 for single precision and 1023 for double precision, used to represent negative exponents.
- mantissa digits
- The binary significant digits after the decimal point, 23 bits for single precision and 52 bits for double precision, determine the precision of the value.
- Normalized number
- The normal case where the exponent bits are neither all 0s nor all 1s, in which case the integer bit 1 is implied and is written in the form of 1.mantissa .
- denormalized number
- When the exponent bits are all 0 and the mantissa is not 0, it is used to represent a number smaller than the minimum normalized number, and the accuracy will be reduced.
- NaN
- Non-numeric, the exponent bits are all 1 and the mantissa is not 0. Any comparison with NaN returns false, and special methods are required for judgment.
- infinity
- The exponent bits are all 1 and the mantissa is 0, indicating an overflow result, which can be divided into positive and negative.
- rounding error
- The deviation caused by truncation or rounding when converting decimal fractions into binary may affect the comparison results after accumulation.
🔗 All keywords and tutorials
❓ FAQ
- How to quickly determine positive or negative after seeing a bit string?
- Look at the first bit: 0 is positive, 1 is negative. This is the only bit that determines the sign, regardless of the size of the value.
- How can I tell that the bit string is zero??
- When the exponent segment and the mantissa segment are all 0 at the same time, it means zero. When the sign bit is 1, it means negative zero. The tool will directly mark the category.