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 HexaDecimal from user. We define a method as convert() to convert the user’s input to Binary.
Here is the source code of the Java Program to Convert Hexadecimal to Binary. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
System.out.println("HexaDecimal to Binary");
scan = new Scanner(System.in);
System.out.println("\nEnter the number :");
num = Integer.parseInt(scan.nextLine(), 16);
String binary = Integer.toBinaryString(num);
System.out.println("Binary Value is : " + binary);
public static void main(String args)
Hexa_Binary obj = new Hexa_Binary();
$ javac MainClass.java $ java MainClass HexaDecimal to Binary Enter the number : 20 Binary Value is : 100000
Sanfoundry Global Education & Learning Series – 1000 Java Programs.