In this section, you will learn to convert binary data into hexadecimal. The java.lang package provides the functionality to convert the binary data into hexadecimal.
Description of the program:
This program takes a binary data from user, which is a string type that is converted into the long data using the parseLong() method. It takes string type value and converts it into a long data. The condition [ if(rem != 0 && rem != 1) ] checks whether the given number is binary number or not. If the given number is either '0' or '1' , program converts the binary data into hexadecimal using toHexaString() method. If fails, it displays a message "This is not a binary number" or "Please try once again.".
This is the method that takes an integer type value and converts it into binary to hexadecimal. The base of hexadecimal is 16.
Here is the code of this program:
Output of this program:
Enter the Binary number:
Hexa decimal: 7f
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial