# Computer question: little-endian and two's complements

**URL:** <https://boards.straightdope.com/t/computer-question-little-endian-and-twos-complements/280399>\
**Category:** Factual Questions\
**Created:** [December 17, 2004, 7:21pm UTC](https://boards.straightdope.com/t/computer-question-little-endian-and-twos-complements/280399 "2004-12-17T19:21:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skeptico](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@Skeptico](https://boards.straightdope.com/u/Skeptico)\
**Post date:** [December 17, 2004, 7:21pm UTC](https://boards.straightdope.com/t/computer-question-little-endian-and-twos-complements/280399/1 "2004-12-17T19:21:35Z")

</div>

Hello,

I’m trying to convert a 4-byte IEEE 745 floating point in an little-endian machine  
(Intel) back into a format readable by humans. According to a little conversion program, the bit pattern (in hex):

80BEBF39 (with 80 at the lowest address)

corresponds to:

3.6572292e-04

I just can’t seem to get that result when I convert by hand. I start by converting  
the number back to big-endian (39BFBE80); then convert that to binary  
(111001101111111011111010000000); and then isolate the fractional  
part of the number, bits 9-31, (101111111011111010000000); and then  
doing a reverse two’s complement by inverting all bits and adding 1  
(10000000100000110000000); and finally convert that number back to  
decimal (4211072). As you can see, what I get is different from what  
I’m expecting (36572292). Any programmers out there can help me?

---

<div class="post-metadata">

**Author:** ![c\_goat](https://avatars.discourse-cdn.com/v4/letter/c/f4b2a3/32.png) [@c\_goat](https://boards.straightdope.com/u/c_goat)\
**Post date:** [December 17, 2004, 8:38pm UTC](https://boards.straightdope.com/t/computer-question-little-endian-and-twos-complements/280399/2 "2004-12-17T20:38:02Z")

</div>

According to [this](http://www.psc.edu/general/software/packages/ieee/ieee.html) site, you took the wrong bits (bits 9-31 actually starts at the tenth bit), and you’re converting the fractional part wrong.

39BFBE80 = 0011 1001 1011 1111 1011 1110 1000 0000

Break it into the 3 parts

Sign Bit (Bit 0) = 0  
Exponent (Bits 1-8) = 0111 0011  
Fractional (Bits 9-31) = 011 1111 1011 1110 1000 0000

The linked site says you add a “1.” to the front of the fractional part, then convert it. Nothing about taking 2’s complement.

I’ll stop there because 1.01111111011111010000000 isn’t a fun conversion. First position after the decimal is 1/2, next is 1/4, next is 1/8 etc.

On preview, you can put your decimal value into [this](http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html) site and you’ll see the breakdown (use the rounded button to get your exact one).
