Big Moose Saloon
 Search | Java FAQ | Recent Topics Register / Login

# How do you convert dcimal to octal??

Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1241
How do you convert dcimal to octal??

thanks.
n sky
Greenhorn

Joined: Oct 04, 2001
Posts: 3
personally, i'd tend to use a scientific calculator -- but if you don't have one available, the other easy thing to do would be to write a small utility in java to do it for you -- in fact, there's at least one utility class that already does most of the work for you, with the signature:
public static String toOctalString(int i) // for strings
http://www.science-ebooks.com/electronics/new_page_12.htm
hope that helps, :-)
--- n sky ---
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1241
oh no.. by hand.
Anyone know a easy method to do it on paper?
vivek j alva
Greenhorn

Joined: Oct 12, 2001
Posts: 3
for example say 35 is decimal number.
than octal form of it would be 43.
you have to divide 35 by 8 your remainder=3 qotient=4
again
divide qotient by 8 your remainder=4 qotient=0
now read remainder from down to up.
you will get 43.
Mr Iftikhar
Ranch Hand

Joined: Oct 12, 2001
Posts: 39

System.out.println(Integer.toOctalString(9));
This will print the octal equivalent of decimal 9.
or you can save you value.
String s = Integer.toOctalString(9);

java language
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Fei,
I've got some notes at http://www.janeg.ca/scjp/oper/binhex.html that might help.
------------------
Jane Griscti
Sun Certified Programmer for the Javaï¿½ 2 Platform

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1241
thanks Jane Griscti!!!