Home Java Java-conversion Convert Hexadecimal number into Integer
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Convert Hexadecimal number into Integer

Advertisement
In this section, you will learn to convert hexadecimal data into integer.

Convert Hexadecimal number into Integer 

     

In this section, you will learn to convert hexadecimal data into integer. The java.lang package provides the functionally to convert the hexadecimal data into an integer type data. 

Code Description:

The following program takes an integer type data at the console (using the keyboard) and converts the hexadecimal data into an integer type data using valueOf() method. It take a number as a string. It converts the number into an integer data using the Integer.valueOf() method.  

Integer.valueOf() :The Integer.valueOf() returns an integer object containing  the value extracted from the specified String. The result is an integer that represents the integer value specified by the string .

Here is full code of this program:

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

public class  HexaToInteger{
  public static void main(String[] argsthrows IOException{
  BufferedReader read = 
 
new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the hexadecimal value:!");
  String s = read.readLine();
  int i = Integer.valueOf(s, 16).intValue();
  System.out.println("Integer:=" + i);
  }
}

Download this program:

Output of this program. 

C:\corejava>java HexaToInteger
Enter the hexadecimal value:!
24
Integer:=36
C:\corejava>
Advertisement

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: June 15, 2007

Ask Questions?    Discuss: Convert Hexadecimal number into Integer   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
haseeb khan
June 14, 2011
gota soveld problamo

i think its very clear idea that i got thanks to you who get solved this problem
sandeep
June 15, 2011
c++

enter an integer number from the user and convert it into hexadecimal
Rizan
August 18, 2011
will not work

It will not work for a hexa decimal value which contians alphabets eg: E34F2
DMCA.com