Conversion issue

Hi all, I am having a doubt in the questions involving hexadecimal numbers. i had this question in a mock exam

int ab = 0xFFFFFFFA; int invertedA = ~ab;

Now how am i supposed to find value of ab which is -6,i mean am is supposed to write A * 16^0 + F * 16^1 + F * 16^2 and so on ??? i don't think this is the proper way,is there no easier way ? how will i get -6 as the answer. plz. solve my doubt, thanks in advance.

"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister

First, I believe the answer is 5, not -6. To see how to do the inversion easily, picture what this number looks like in binary. It is: 11111111 11111111 11111111 11111010 Inverting means 1 becomes 0 and vice versa: 00000000 00000000 00000000 00000101 or 101 for short, which is to say 5.

Don't forget!!! Two's complement means you need to invert the number and then add 1! So -->

11111111 11111111 11111111 11111010 00000000 00000000 00000000 00000101 + 1 ----------------------------------- 00000000 00000000 00000000 00000110 == 6 So that means it really is -6 But I agree -- the easiest way I've found to convert hex digits is first to convert it to binary then two's complement it (if its negative) and then figure out the decimal representation.

Thanks all Jessica the number given ab is itself -6 according to 2's complement . then after the operation int invertedA = ~ab; it comes to sign change and answer as 5 Thanks all for your answers, happy preparation,