2 Replies - 4021 Views - Last Post: 21 February 2010 - 02:59 PM Rate Topic: -----

#1 Guest_bobby*


Reputation:

Decimal to octal using Mod and Integer division in java

Posted 21 February 2010 - 02:02 PM

I need help. I need to convert decimal to octal using mod and integer division. anyone got a suggestion for me?
Is This A Good Question/Topic? 0

Replies To: Decimal to octal using Mod and Integer division in java

#2 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Decimal to octal using Mod and Integer division in java

Posted 21 February 2010 - 02:08 PM

Think it through mathematically, write some pseudocode if you need to, and then convert it into Java.

Here's a link which shows you how to do it by hand, which might help you write the code http://www.searchmar...-other-base.php
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Decimal to octal using Mod and Integer division in java

Posted 21 February 2010 - 02:59 PM

View Postbobby, on 21 February 2010 - 03:02 PM, said:

I need help. I need to convert decimal to octal using mod and integer division. anyone got a suggestion for me?

That will print it in reverse order.... let you figure out how to make it the good way
int number = 12345678;
while(number ! = 0) {
  int digit = number % 8;
  System.out.print("" + digit);
  number /= 8;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1