This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing decimal to octale (and etc.)  RSS feed

 
Justin Porter
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, what is the object/command that I need in order to change a decimal number to octale, or to binary, or to hexidecimal, etc. Is there a command like Integer.toOctale? Thanks in advance!
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Justin -

Thre's no such number system as "octale".

If you're looking for "octal", do you want the number or the string representation of the number?

Cheers,

Jeff
 
Justin Porter
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either would work, string respresentation would be nice but I'd like to know both. Thanks!
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have an int, you can get the String representation with:



Or you can get the number if you started with a String with:



These are both static methods of class Integer, so you don't need an Integer object. There are other ways to do this, but these give you the general idea. I highly recommend getting familiar with the API docs, because you could have found the answer on your own in about a minute.
 
Justin Porter
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeff, I'll try that out!
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. You're welcome!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!