The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
Please vote in the Forum Structure Poll. Polling will close at 2PM EST on January 21, 2025.

Two's Complement Hex to Dec

EvigilantEvigilant VARegistered User regular
edited September 2009 in Help / Advice Forum
*edit: To clarify, I'm not really asking for the exact answers, but if I'm right or wrong in the method. If I'm wrong, I'd like to know what I'm doing wrong so I can figure out the answer on my own.


I'm having a brain fart and my google-fu is failing me. I'm trying to show the decimal value of each number, given that it's a two's complement, hexadecimal 16bit int. This is supposed to be review, but I'm having trouble remembering all of it. So if I understand this correctly at 3am:


a) 25A7
0010 0101 1010 0111 => 9639

b) 90B3
1001 0000 1011 0011
0110 1111 0100 1100 +1
0110 1111 0100 1101 ?? <- is that right? this doesn't seem right since 37043 is out of the acceptable range. Or is it -28493? I'm having trouble mainly with this one.

c) FF3E
1111 1111 0011 1110
0000 0000 1100 0001 +1
0000 0000 1100 0010 => -194 (is this correct as well?)

d) 7753
0111 0111 0101 0011 => 30547

and then the negative for each hex would be:

a) 25A7
0010 0101 1010 0111
1101 1010 0101 1000 +1
1101 1010 0101 1001 = DA59

b) 90B3
1001 0000 1011 0011
0110 1111 0100 1100 +1
0110 1111 0100 1101 = 6F4D

c) FF3E
1111 1111 0011 1110
0000 0000 1100 0001 +1
0000 0000 1100 0010 = 00C2

d) 7753
0111 0111 0101 0011
1000 1000 1010 1100 +1
1000 1000 1010 1101 = 88AD

XBL\PSN\Steam\Origin: Evigilant
Evigilant on

Posts

  • ecco the dolphinecco the dolphin Registered User regular
    edited September 2009
    Evigilant wrote: »
    b) 90B3
    1001 0000 1011 0011
    0110 1111 0100 1100 +1
    0110 1111 0100 1101 ?? <- is that right? this doesn't seem right since 37043 is out of the acceptable range. Or is it -28493? I'm having trouble mainly with this one.

    It's got a one set in its highest bit, so it is a negative number. It won't be 37,043 since that is a positive number, so...
    Evigilant wrote: »
    c) FF3E
    1111 1111 0011 1110
    0000 0000 1100 0001 +1
    0000 0000 1100 0010 => -194 (is this correct as well?)

    Yup.
    Evigilant wrote: »
    and then the negative for each hex would be:
    ...

    Looks about right.

    If you're on Windows, try using the calc (switch into scientific mode) to double check your answers.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • EvigilantEvigilant VARegistered User regular
    edited September 2009
    Thank you ecco, that's exactly what I needed.

    Evigilant on
    XBL\PSN\Steam\Origin: Evigilant
Sign In or Register to comment.