Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

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

Evigilant on
Google+ Profile XBL\PSN\Steam\Origin: Evigilant

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.

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

    Google+ Profile XBL\PSN\Steam\Origin: Evigilant
Sign In or Register to comment.