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
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# basic question about binary, oct and Hex

Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:
Could you help me out in re-collecting basic things about converting a decimal to octal and hexadecimal formats. How to represent negative integers into binary format.

Srini

Author and all-around good cowpoke
Posts: 13078
6
• Number of slices to send:
Optional 'thank-you' note:
The java.lang.Integer and .Long wrapper classes have methods like
String Integer.toHexString( x );
toBinaryString( x ) and toOctalString( x )
Bill

Ranch Hand
Posts: 3141
• Number of slices to send:
Optional 'thank-you' note:
Hi Srini,
Here's a link to some notes I made on working with different number systems
Hope they help.
------------------
Jane
[This message has been edited by Jane Griscti (edited October 07, 2000).]

Ranch Hand
Posts: 44
• Number of slices to send:
Optional 'thank-you' note:
I noticed jane's link didn't work so I give you just the quick basics:
octal is a base eight conversion and hex is base 16 and binary is base 2.
so for binary
32 16 8 4 2 1
-------------------
0 1 1 0 1 0 is 36 in decimal.
so for octal
8^6 8^5 8^4 8^3 8^2 8 1
-------------------------------
Octal of 3 1
--------------------------------
24 + 1 = 25 Decimal
so for hex
16^4 16^3 16^2 16 1
----------------------------------
Hex of F F
---------------------------------
(16*15) + (1*15) = 255 decimal
Java uses two's compliment to produce a negative number, this is done by taking the positive representation of the value in binary and then bitwise them(Reverse them) and then add one to the value. This will give you the negative value.
Hope this helps out....

Greenhorn
Posts: 5
• Number of slices to send:
Optional 'thank-you' note:
Hi Srini,
http://www.rz.uni-hohenheim.de/rz/sys/basics/csc102/ch3.html#con_hex_oct_bin
Hope this helps you.
Thanks.
Vijay

 I will open the floodgates of his own worst nightmare! All in a tiny ad: a bit of art, as a gift, that will fit in a stocking https://gardener-gift.com