Monday, August 4, 2008

Java Tricks: Converting a number from one base to another

Converting a number int n from base b(<20) to base 10

Integer.parseInt(""+n,b);

Converting a number int n from base 10 to base 2, 8 or 16

Integer.toBinaryString(n);
Integer.toOctalString(n);
Integer.toHexString(n);

No comments: