We make a class with two methods one for input and other for conversion and access this by object of this class. We first take the input as Binary from user. We define a method as convert() to convert the user’s input to HexaDecimal.
Here is the source code of the Java Program to Convert Binary to Hexadecimal. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
System.out.println("Binary to HexaDecimal");
scan = new Scanner(System.in);
System.out.println("\nEnter the number :");
num = Integer.parseInt(scan.nextLine(), 2);
String hexa = Integer.toHexString(num);
System.out.println("HexaDecimal Value is : " + hexa);
public static void main(String... q)
Binary_Hexa obj = new Binary_Hexa();
$ javac Main_Class.java $ java Main_Class Binary to HexaDecimal Enter the number : 1010 HexaDecimal Value is : a
Sanfoundry Global Education & Learning Series – 1000 Java Programs.