0
3.1kviews
How To Convert Binary to Hexadecimal in Java
1 Answer
0
50views

Let's see the example of how to convert binary to hexadecimal in java.

import java.util.Scanner;
class BinaryToHexadecimal
{
int number;
Scanner s;

void takeBinaryValue()
{
s = new Scanner(System.in);
System.out.println("Enter the binary value");
number = Integer.parseInt(s.nextLine(), 2);
}

void conversion()
{
String hexa = Integer.toHexString(number);
System.out.println("hexadecimal value is: "+hexa);
}

public static void main(String args[])
{
BinaryToHexadecimal bh = new BinaryToHexadecimal();
bh.takeBinaryValue();
bh.conversion();
}
}

Output:

Enter the binary value

101010

Hexadecimal value is:  2a
Please log in to add an answer.