Decimal to binary, octal to decimal
Hello to all!
I am new on this forum, and I am quite new to Java too. I am from Slovenia, and I don't speak English very well, so please excuse me for mistakes.
Ok, for homework I have to write a program, which convert from decimal to binary and than another program, which convert from octal to decimal.
In the program which convert from decimal to binary, I have to use while loop, and this is a problem. I know how to do it with toBinaryString(), but I don't have idea, how to do it with While loop.
So, write this program, to convert from decimal to binary. The Binary number is save in variable a, but I have no Idea how to revese it. Now, the (Decimal) 55 = (Binary)111011, but it is wrong, it have to be 110111. How can I reverse this number?
And now, I have got another question. I have no Idea, how to convert from Octal to Decimal. In this case isn't necessarily to use While loop, I should use any of method, if they exists. :) But it is to complicated for me, so, if you have any idea, i will be happy.
public class Convert
public static void main(String args)
Scanner in = new Scanner(System.in);
System.out.println("Input decimal number: ");
int dec = in.nextInt();
int udec = dec;
String a = new String();
while (udec >= 1)
ost = udec % 2;
a = ost + "";
Thanks to all!