Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login

# how to convert decimals to octal and hexadecimal?

Karthik Gurunathan
Greenhorn

Joined: Jan 26, 2004
Posts: 19
Hi there ,
Thanks,
karhik
Ranch Hand

Joined: Feb 17, 2004
Posts: 170
Hi Karthik,
In Java language you can do that using he methods
toOctalString(),toHexString(),toBinaryString methods of the Integer and Long classes.
Or are you looking for the general rules of conversion?

PMP CSQA SCJP SCWCD SCBCD INS 21 INS 23
Karthik Gurunathan
Greenhorn

Joined: Jan 26, 2004
Posts: 19
Hi sekar,
I understand that ,...I am looking for general method of conversion ..exam point of view..if they ask like whats the hexadecimal equivalent for some particular decimal..stuff like that...
karthik
Sandhya Harish
Greenhorn

Joined: Feb 15, 2002
Posts: 22
to convert a decimal to octal :
say the decimal number was 70
- 70/8 = 8, remainder = 6
- 8/8 = 1, remainder = 0
- 1/8 = 0, remainder = 1
therefore, octal eqv of 70 is 0106, u can recheck this by
0*8^3 + 1*8^2 + 0*8^1 + 6*8^0 = 0+64+0+6 = 70
to convert a decimal to hexadecimal:
say the decimal number is 125
- 125/16 = 7, remainder = D(13)
- 7/16 = 0, remainder = 7
therefore, hexadecimal equivalent of 125 is 7D, u can recheck this by
7*16^1 + 13*16^0 = 112+13 = 125.
hope this helped!!
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
Karthik-
What you are asking is a very general question, I did a google search for you and came up with lots of hits, they are all worth checking.
How to convert between different base types
If you have a more specific question, we will gladly answer it.

- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!

I agree. Here's the link: http://aspose.com/file-tools

subject: how to convert decimals to octal and hexadecimal?