Home Java Java-conversion Convert Byte to Hexadecimal
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Convert Byte to Hexadecimal

Advertisement
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>
_
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 14, 2008

Related Tutorials

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

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com