I am trying to convert hexadecimal to Binary but the problem is the result is ignoring the zeroes which I should get on the left hand side which are crucial for me.
My code:
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan;
int num;
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);
}
OUTPUT :
When I am giving the input as 0000000000001a000d00
I should get the output as
00000000000000000000000000000000000000000000000000011010000000000000110100000000
But Instead I get 11010000000000000110100000000
leaving the initial zeroes.
How should I get the exact number. Thanks in advance.