0

So I recently learned the way to represent a float into a binary string, and I came across a really annoying confusion.

Lets say I have the float 10.25. In binary this would be 1010.01

Taking the exponents, this would be 1.01001 x 2^(3). So the sign bit is 0, the exponent is the unsigned 8bit binary of 127 + 3, which would become 10000010. Now for the fraction part, this should be 00000000 00000000 0001001 (23 bits)

Putting them all together, 0 10000010 00000000 00000000 0001001.

But when I put this into a conversion website, it gives me this: enter image description here It seems that the Mantissa part has been flipped by each 8 bits, maybe because of the little endian implementation. But here is the thing.

From the Big Endian Mantissa 00000000 00000000 0001001,

shouldn't the Little Endian Mantissa be 10010000 00000000 0000000?

The image says that the binary string is 0 10000010 0100100 00000000 00000000

2
  • If i'm right, big endian and little endian conversion works only with unsigned integers. There are lots of standards of the float management, maybe little endian and big endian systems doesn't use the same standards. Commented Sep 6, 2015 at 23:06
  • 1
    Do you mean a float or a decimal number? Split your number into whole and fractional parts. Convert each to binary string digits separately and put them together afterwards. Commented Sep 6, 2015 at 23:14

1 Answer 1

2

As you correctly wrote

  • the sign is 0
  • the exponent is 10000010
  • the mantissa is 01001000000000000000000 (added a few trailing 0's in order to fill the 32-bit pattern)

Putting these parts together we get

0 10000010 01001000000000000000000

Now, arranging the bits into bytes, we have

01000001 00100100 00000000 00000000

This is exactly the representation of 10.25 according to the IEEE 754 single precision format. In big endian machines the 4 bytes or ordered as above while in little endian machines they are ordered the other way round. That is

  • 10.25 in big endian machines is 01000001 00100100 00000000 00000000
  • 10.25 in little endian machines is 00000000 00000000 00100100 01000001

The IEEE 754 standard specifies that

  • the first bit represents the sign
  • the next 8 bits represents the exponent
  • the remaining bits represents the mantissa minus 1

IEEE 754

If m1..m23 are the bits making up the mantissa, then m1 weighs 2^-1 and m23 weighs 2^-23.
Simply, it's the standard that dictates the meaning of each bit.

Sign up to request clarification or add additional context in comments.

3 Comments

My confusion is, why is the mantissa 01001000 00000000 0000000 in the first place? we have that 10.25 = 1010.01 = 1.01001 x 2^3, so shouldn't the 23 bit Mantissa be 00000000 00000000 0001001? Why does the 01001 go in the first part of the 23 bit Mantissa?
@user3467433 Would you agree that, if someone gave you 32 spaces to fill out with the decimal number 3.1415926, that you would write it as 3 . 141592600000000000000000000000 and not 3 . 000000000000000000000001415926, since those are different numbers?
Oh, I simply mis-understood the mantissa part of the IEEE 754 standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.