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

Ranch Hand
Posts: 18944
• Number of slices to send:
Optional 'thank-you' note:
How to represent negative hexadecimal and octal numbers?
decimal binary hex octal
25 00011001 0x19 031
-25 11100111 ? ?
Anyone could please throw light on this?

Anonymous
Ranch Hand
Posts: 18944
• Number of slices to send:
Optional 'thank-you' note:
hi nikita,
lets take a simple number -15. since u already know how to convert this to binary i will not harp on this issue.
the binary for -15 is 1111 1111 1111 1111 1111 1111 1111 0001
1111 gives us 2^3+2^2+2^1+2^0 = 15
now 15 is represented in hex as f
and 0001 gives us 1
now 1 is represented in hex as 1
so -15 in hex is 0xf1

in octal however it takes 3 bits thus -15 in this case is

11 111 111 111 111 111 111 111 111 110 001
ie
3 7 7 7 7 7 7 7 7 6 1
or 37777777761
here is a program to check this up
class demo
{
public static void main(String[] args)
{int i=-15;
System.out.println(Integer.toHexString(i));
System.out.println(Integer.toOctalString(-15));
}
}
regds.
Rahul.

[This message has been edited by rahul_mkar (edited June 29, 2000).]

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.