Home Java Java-conversion Convert Byte to Hexadecimal



Convert Byte to Hexadecimal
Posted on: March 14, 2008 at 12:00 AM
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.

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[] args) throws 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>
_

Related Tags for Convert Byte to Hexadecimal:
javacstringideconversionfunctionconsolescriptinputconvertfunioparseintegermethodversionhexipvidecimalvaluenumberusingolebyteintthisidpackagefunctionalhexadecimalforuncprogramtoramcilandescriptioneitdesrsisectionliputimfrominasmntpartrjpackadesfuncagemeintoproackxsxassopackisparseintgofunctionalityandarcodcodeconsstrrtrtsvascrssriringripthavstaluprndodeonomogrolonp


More Tutorials from this section

Ask Questions?    Discuss: Convert Byte to Hexadecimal   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.