tengtium
Posts: 3
Nickname: tengtium
Registered: Feb, 2003
|
|
Re: Code for converting binary to hexidecimal
|
Posted: Feb 4, 2003 10:45 PM
|
|
try this program:
public class NumberSystem { public static void main(String[] s) { int num = 15; // convert decimal to hex string System.out.println(Integer.toHexString(num)); // convert decimal to binary string System.out.println(Integer.toBinaryString(num)); // convert decimal to octal string System.out.println(Integer.toOctalString(num));
// convert octal string to decimal integer System.out.println(Integer.parseInt("17", 8)); // convert hex string to decimal integer System.out.println(Integer.parseInt("F", 16)); // convert binary string to decimal integer System.out.println(Integer.parseInt("1111",2)); // convert decimal string to decimal integer System.out.println(Integer.parseInt("15",10));
// convert binary to decimal integer System.out.println(Integer.valueOf("1111", 2)); // convert octal to decimal System.out.println(Integer.valueOf("17", 8)); // convert hex to decimal System.out.println(Integer.valueOf("F", 16)); // convert decimal to decimal System.out.println(Integer.valueOf("15", 10));
System.out.println(Integer.decode("F#")); } }
|
|