|
public class Integerdemo {
public static void Main (string[] args) {
decimal to binary, octal, hex
System.out.println (integer.tobinarystring (100));
System.out.println (integer.tooctalstring (100));
System.out.println (integer.tohexstring (100));
System.out.println ("-------------------------");
decimal to another binary
System.out.println (integer.tostring (100, 10));
System.out.println (integer.tostring (100, 2));
System.out.println (integer.tostring (100, 8));
System.out.println (integer.tostring (100, 16));
System.out.println (integer.tostring (100, 5));
System.out.println (integer.tostring (100, 7));
System.out.println (integer.tostring (100,-7));
System.out.println (integer.tostring (100, 70));
System.out.println (integer.tostring (100, 1));
System.out.println (integer.tostring (100, 17));
System.out.println (integer.tostring (100, 32));
System.out.println (integer.tostring (100, 37));
System.out.println (integer.tostring (100, 36));
System.out.println ("-------------------------");
other binary to decimal
System.out.println (Integer.parseint ("100", 10));
System.out.println (Integer.parseint ("100", 2));
System.out.println (Integer.parseint ("100", 8));
System.out.println (Integer.parseint ("100", 16));
System.out.println (Integer.parseint ("100", 23));
NumberFormatException
System.out.println (Integer.parseint ("123", 2));
}
}
|