bnntd
bnntd

Reputation: 43

How does the number 0 look like in binary float format?

The float format (IEEE) has 32 bits. First bit for the sign, after that 8 bits for a biased exponent and after that another 23 bits for the mantissa. In this mantissa is the first 1 (is always 1) always hidden which leads me to my question:

how does the number 0 look like in this format? because if the exponents 0 the number will always be 1. plus the mantissa is always minimum 1 right? If they are only zeros in the mantissa it will count as '1.0'...

I really don't get this.

Upvotes: 4

Views: 9372

Answers (3)

Mathias
Mathias

Reputation: 1500

Wikipedia tells you:

0000 0000   = 0
8000 0000   = −0

Besides the normal float values, with exponent and mantisse there are a bunch of other irregular numbers like zero, infinity and a bunch of NaNs. There are also subnormal numbers; where numbers below 2^-127 are approximated with fixed instead of a floating exponent.

Actually, zero is a normal subnormal number. Subnormals are encoded with as (−1)signbits×2^−126 × 0.significandbits and exponent all zero. If significantbits is zero, the result is (+/-) zero.

Upvotes: 6

Patricia Shanahan
Patricia Shanahan

Reputation: 26185

IEEE 754 binary floats with the biased exponent zero are not normalized, and there is no implicit one-bit before the binary point in the significand. Zero significand means 0.0 * 2^x, not 1.0 * 2^x.

Upvotes: 3

Yu Hao
Yu Hao

Reputation: 122503

Zero values are represented by the biased exponent and significand both being 0.

The sign could be 0 or 1, representing +0.0 and -0.0 respectively.

For example, the negative zero looks like this:

enter image description here

Upvotes: 2

Related Questions