The Straight Dope

Go Back   Straight Dope Message Board > Main > General Questions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-17-2004, 01:21 PM
Skeptico Skeptico is offline
Guest
 
Join Date: Jul 2002
Computer question: little-endian and two's complements

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?
Reply With Quote
Advertisements  
  #2  
Old 12-17-2004, 02:38 PM
c_goat c_goat is offline
Guest
 
Join Date: Aug 2000
According to this 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 site and you'll see the breakdown (use the rounded button to get your exact one).
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:57 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Send questions for Cecil Adams to: cecil@chicagoreader.com

Send comments about this website to: webmaster@straightdope.com

Terms of Use / Privacy Policy

Advertise on the Straight Dope!
(Your direct line to thousands of the smartest, hippest people on the planet, plus a few total dipsticks.)

Publishers - interested in subscribing to the Straight Dope?
Write to: sdsubscriptions@chicagoreader.com.

Copyright © 2013 Sun-Times Media, LLC.