Page: How To Convert Binary to Hexadecimal in Java
0

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
ADD COMMENTlink
modified 22 months ago by gravatar for Yashbeer Yashbeer170 written 23 months ago by gravatar for anuragsingh07378 anuragsingh0737830
Please log in to add an answer.