This week's giveaway is in the Java/Jakarta EE forum.We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Octals, Decimals and Hexadecimals

Greenhorn
Posts: 4
Could someone show me how to get octal and hexadecimal numbers from decimal ones ? eg. How would you go about getting the octal of 489 and its hexadecimal ?
I really appreciate your help.

Ranch Hand
Posts: 3451
Probably the simplest way is to use the Integer wrapper class. For example:

"The Hood"
Sheriff
Posts: 8521
I think that he means by hand.
Octal uses a ones place, and 8's place, a 64's place, 512 etc. Basically you just need to find out how many of each that you need.
To convert 489 decimal to octal
512's = 0 too big
64's = 7 divide 489 by 64 = 7 remainder 41
8's = 5 divide 41 by 8 = 5 remainder 1
1's = 1
So 489 decimal = 751 octal.
For hex you have 1's, 16's, 256's, 4096's etc.
256's = 1 divide 489 by 256 = 1 remainder 233
16's = 14 (represented by "e") divide 233 by 16 = 14 remainder 9
1's = 9
So 489 decimal = 1e9 hex
[ June 26, 2003: Message edited by: Cindy Glass ]

Ranch Hand
Posts: 67

Originally posted by Cindy Glass:
To convert 489 decimal to octal
512's = 0 too big
64's = 7 divide 489 by 64 = 7 remainder 41 8's = 5 divide 41 by 8 = 5 remainder 1
1's = 1
So 489 decimal = 751 octal.

I learned a different method for converting decimal numbers to other bases--repeated division by the target base:

You repeat the division until the remainder is less than the divisor. Then construct the number by going back up the remainders (7, 5, 1).

Michael Morris
Ranch Hand
Posts: 3451
I think that he means by hand.
Just tryin' to make life a litte easier.

William Alldred
Greenhorn
Posts: 4

Originally posted by Cindy Glass:
I think that he means by hand.
Octal uses a ones place, and 8's place, a 64's place, 512 etc. Basically you just need to find out how many of each that you need.
To convert 489 decimal to octal
512's = 0 too big
64's = 7 divide 489 by 64 = 7 remainder 41
8's = 5 divide 41 by 8 = 5 remainder 1
1's = 1
So 489 decimal = 751 octal.
For hex you have 1's, 16's, 256's, 4096's etc.
256's = 1 divide 489 by 256 = 1 remainder 233
16's = 14 (represented by "e") divide 233 by 16 = 14 remainder 9
1's = 9
So 489 decimal = 1e9 hex
[ June 26, 2003: Message edited by: Cindy Glass ]

William Alldred
Greenhorn
Posts: 4

Originally posted by Michael Morris:
I think that he means by hand.
Just tryin' to make life a litte easier.

yes, I meant by hand. I believe I will need to in the Programmer exam.

Michael Morris
Ranch Hand
Posts: 3451

Originally posted by William Alldred:

yes, I meant by hand. I believe I will need to in the Programmer exam.

I doubt it, unless it's changed significantly. But any programmer should be able to make these conversions without breakin' a sweat.

William Alldred
Greenhorn
Posts: 4

Originally posted by Michael Morris:

I doubt it, unless it's changed significantly. But any programmer should be able to make these conversions without breakin' a sweat.

I seem to remember some practice questions which would require a conversion in order to find the correct answer. However, I hope to God I'm wrong !

 Consider Paul's rocket mass heater.