This is a method of performing base conversion in Java. Since it uses only the standard library, you can copy and paste it immediately.
Java
final String bin = "11111110";
final int dec = Integer.parseInt(bin, 2);
final String oct = Integer.toOctalString(dec);
System.out.println(oct);
output
376
Java
final String bin = "11111110";
final int dec = Integer.parseInt(bin, 2);
System.out.println(dec);
output
254
Java
final String bin = "11111110";
final int dec = Integer.parseInt(bin, 2);
final String hex = Integer.toHexString(dec);
System.out.println(hex);
output
fe
Java
final String bin = "11111110";
final int dec = Integer.parseInt(bin, 2);
final String base32 = Integer.toString(dec, 32);
System.out.println(base32);
output
7u
Java
final String bin = "11111110";
final int dec = Integer.parseInt(bin, 2);
final int n = 36;
final String base36 = Integer.toString(dec, n);
System.out.println(base36);
output
72
Java
final String oct = "376";
final int dec = Integer.parseInt(oct, 8);
final String bin = Integer.toBinaryString(dec);
System.out.println(bin);
output
11111110
Java
final String oct = "376";
final int dec = Integer.parseInt(oct, 8);
System.out.println(dec);
output
254
Java
final String oct = "376";
final int dec = Integer.parseInt(oct, 8);
final String hex = Integer.toHexString(dec);
System.out.println(hex);
output
fe
Java
final String oct = "376";
final int dec = Integer.parseInt(oct, 8);
final String base32 = Integer.toString(dec, 32);
System.out.println(base32);
output
7u
Java
final String oct = "376";
final int dec = Integer.parseInt(oct, 8);
final int n = 36;
final String base36 = Integer.toString(dec, n);
System.out.println(base36);
output
72
Java
final int dec = 254;
final String bin = Integer.toBinaryString(dec);
System.out.println(bin);
output
11111110
Java
final int dec = 254;
final String oct = Integer.toOctalString(dec);
System.out.println(oct);
output
376
Java
final int dec = 254;
final String hex = Integer.toHexString(dec);
System.out.println(hex);
output
fe
Java
final int dec = 254;
final String base32 = Integer.toString(dec, 32);
System.out.println(base32);
output
7u
Java
final int dec = 254;
final int n = 36;
final String base36 = Integer.toString(dec, n);
System.out.println(base36);
output
72
Java
final String hex = "fe";
final int dec = Integer.parseInt(hex, 16);
final String bin = Integer.toBinaryString(dec);
System.out.println(bin);
output
11111110
Java
final String hex = "fe";
final int dec = Integer.parseInt(hex, 16);
final String oct = Integer.toOctalString(dec);
System.out.println(oct);
output
376
Java
final String hex = "fe";
final int dec = Integer.parseInt(hex, 16);
System.out.println(dec);
output
254
Java
final String hex = "fe";
final int dec = Integer.parseInt(hex, 16);
final String base32 = Integer.toString(dec, 32);
System.out.println(base32);
output
7u
Java
final String hex = "fe";
final int dec = Integer.parseInt(hex, 16);
final int n = 36;
final String base36 = Integer.toString(dec, n);
System.out.println(base36);
output
72
Java
final String base32 = "7u";
final int dec = Integer.parseInt(base32, 32);
final String bin = Integer.toBinaryString(dec);
System.out.println(bin);
output
11111110
Java
final String base32 = "7u";
final int dec = Integer.parseInt(base32, 32);
final String oct = Integer.toOctalString(dec);
System.out.println(oct);
output
376
Java
final String base32 = "7u";
final int dec = Integer.parseInt(base32, 32);
System.out.println(dec);
output
254
Java
final String base32 = "7u";
final int dec = Integer.parseInt(base32, 32);
final String hex = Integer.toHexString(dec);
System.out.println(hex);
output
fe
Java
final String base32 = "7u";
final int dec = Integer.parseInt(base32, 32);
final int n = 36;
final String base36 = Integer.toString(dec, n);
System.out.println(base36);
output
72
Java
final String base36 = "72";
final int n = 36;
final int dec = Integer.parseInt(base36, n);
final String bin = Integer.toBinaryString(dec);
System.out.println(bin);
output
11111110
Java
final String base36 = "72";
final int n = 36;
final int dec = Integer.parseInt(base36, n);
final String oct = Integer.toOctalString(dec);
System.out.println(oct);
output
376
Java
final String base36 = "72";
final int n = 36;
final int dec = Integer.parseInt(base36, n);
System.out.println(dec);
output
254
Java
final String base36 = "72";
final int n = 36;
final int dec = Integer.parseInt(base36, n);
final String hex = Integer.toHexString(dec);
System.out.println(hex);
output
fe
Java
final String base36 = "72";
final int n = 36;
final int dec = Integer.parseInt(base36, n);
final String base32 = Integer.toString(dec, 32);
System.out.println(base32);
output
7u
Java
final String base36 = "72";
final int n = 36;
final int dec = Integer.parseInt(base36, n);
final int m = 3;
final String base3 = Integer.toString(dec, m);
System.out.println(base3);
output
100102
Recommended Posts