Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

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.

Ads

Tutorials   
Ads

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

Share on Google+Share on Google+

Convert Byte to Hexadecimal

Posted on: March 14, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Convert Byte to Hexadecimal   View All Comments

Post your Comment


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

Ads

 

Ads