Convert Hexadecimal number into Integer

Ads
 

Convert Hexadecimal number into Integer

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

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>

Ads

Ads