0
3.4kviews
written 7.0 years ago by |
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