Help coderanch get a
new server
by contributing to the fundraiser
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Paul Clapham
• Devaka Cooray
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• paul wheaton
• Henry Wong
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Tim Moores
• Carey Brown
• Mikalai Zaikin
Bartenders:
• Lou Hamers
• Piet Souris
• Frits Walraven

# conversion of negative numbers to octal/hex

Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:
Hi,

Thanks,
Sarika.

author
Posts: 23956
142
• Number of slices to send:
Optional 'thank-you' note:

Originally posted by Sarikaa Bhatnagar:
Hi,

Thanks,
Sarika.

Hmmm.... Interesting question. How would you do it?

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

Sarikaa Bhatnagar
Greenhorn
Posts: 26
• Number of slices to send:
Optional 'thank-you' note:
Thanks a lot!!! I am really grateful.

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?