[an error occurred while processing this directive]

Convert Byte to Hexadecimal

                         

In this section, We are going to convert a byte value into a hexadecimal number. The package java.lang provides the functionality for this conversion.

Code Description: This program takes a byte number from console as input and converts it into the hexadecimal by using the toHexString() method. The method Integer.parseInt() takes a string as input and converts it into an integer number.

Here is the code of this program

 

 

 

import java.io.*;
import java.lang.*;

public class ByteToHexa{
  public static void main(String[] argsthrows IOException{
    BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the byte number:");
    byte b =(byte)6;
    String str = buff.readLine();
    int i =Integer.parseInt(str);
    String hexString = Integer.toHexString(i);
    System.out.println("Hexa is:=" + hexString);
  }
}

Download this program:

Output this program.

C:\corejava>java ByteToHexa
Enter the byte number:
31
Hexa is:=1f
C:\corejava>
_

                         

[an error occurred while processing this directive]