Originally posted by Sarikaa Bhatnagar:
Hi,
Can anyone please help me with the conversion of decimal -20 (negative 20) to octal and hexadecimal and vice versa.
Thanks,
Sarika.
Hmmm.... Interesting question. How would you do it?
Let's start with 20 in binary: (Somebody please check my math here!)
20 = 0000 0000 0001 0100
Go through 2's complement to find -20 in binary:
~20 = 1111 1111 1110 1011
~20 + 1 = -20 = 1111 1111 1110 1100
For Hexidecimal, just convert every group of 4 bits:
-20 = F F E C = 0xFFEC
For Octal, just convert every group of 3 bits:
-20 = 1 111 111 111 101 100
-20 = 1 7 7 7 5 4 = 0177754
Whew!! Hope I got my math right ...
Henry