rawr rang
rawr rang

Reputation: 973

Understanding the mantissa part of a 32 bit float for the decimal 0.2

Why is 0.2d equal to a binary representation of: 0 0111110010011001100110011001101

So 0.2d can translate into 0.0011b repeating. You move the radix over and get 1.1 x 2^-3

sign bit = 0

exponent = 0111 1100

mantissa = 10011001100110011001101 why?

Wouldn't the mantissa just be 10000000000000000000000?

Upvotes: 0

Views: 1051

Answers (1)

Chris Dodd
Chris Dodd

Reputation: 126378

0.2 decimal is 0.001100110011... in binary. When you shift that have a 1 before the decimal point (required, as that 1 is not actually stored in the fp value -- its the "hidden" one), you have 2-3 · 1.1001100110011... Now if you actually want to store exactly 23 bits of mantissa (as with fp32), the break:

10011001100110011001100_110011001..

comes at a point just before a 1 bit, so you round that up, giving

10011001100110011001101

as the stored mantissa

Upvotes: 1

Related Questions