Integer and Long wrapper classes let you convert numbers in base 10 to other bases.
public class MainClass{
public static void main(String[] argv){
String s3 = Integer.toHexString(254); // convert 254 to hex
System.out.println("254 is " + s3); // result: "254 is fe"
String s4 = Long.toOctalString(254); // convert 254 to octal
System.out.print("254(oct) ="+ s4); // result: "254(oct) =376"
}
}
|