Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Octals, Decimals and Hexadecimals

 
William Alldred
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably the simplest way is to use the Integer wrapper class. For example:
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Richard Jensen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that he means by hand.
Just tryin' to make life a litte easier.
 
William Alldred
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic