1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Decimal to Binary 32 bit signed conversion

  1. Mar 7, 2013 #1
    1. The problem statement, all variables and given/known data
    Convert -89 to 32 bit representation (2-complement for negative numbers)

    my answer does not agree with calculated answers from multiple conversion sites.

    2. Relevant equations



    3. The attempt at a solution

    to get the exponent i figured out the closest 2 exponent to 89, which is 7.

    then I added the exponent to the bias, 127 + 7 = 134

    therefore 134 to binary would be: (I added underscores to separate the sign/exponent and mantissa

    1__________1 0 0 0 0 1 1 0___________0 1 1 0 0 1
    sign___________exponent______________ mantissa

    the only problem is when i check my answer on multiple sites, the answer is

    1 __________1 0 0 0 0 1 0 1 ___________0 1 1 0 0 1

    _____________________^---exponent they have adds up to 133 ?

    what am I doing wrong?
     
  2. jcsd
  3. Mar 7, 2013 #2

    Mark44

    Staff: Mentor

    Why are you converting to floating point form? The number you need to convert is an integer. You're making this much harder than it actually needs to be.
     
  4. Mar 8, 2013 #3

    vela

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    As Mark44 noted, you're solving the wrong problem. :wink:

    But to answer the question you asked anyway, you don't want 27. You want 26, the power of 2 that's closest to 89 but less than or equal to 89. This gives you
    $$89 = 1.390625 \times 2^{64}$$ which has a mantissa with the integer part equal to 1, which is what you want if you're going to convert to floating-point format.
     
  5. Mar 8, 2013 #4

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    2^64? I think you blew my mind

    89 = 1.390625 * 64
     
  6. Mar 8, 2013 #5

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    Hint: convert 89 to Hex.
     
  7. Mar 8, 2013 #6

    Mark44

    Staff: Mentor

    vela was thinking 6 but mistakenly wrote 64.
     
  8. Mar 8, 2013 #7

    vela

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Education Advisor

    Oops. Thanks for catching that.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted