Code Snippets
JAVA Code Snippets
Java program to convert Hexadecimal String to Decimal Integer
By: IncludeHelp, On 02 OCT 2016
In this code snippet/program we will learn how we can convert a hexadecimal string into its equivalent decimal integer.
In this program we will read a hexadecimal value using Scanner class and will convert entered hexadecimal value to integer value using Integer.parseInt() method.
//Java program to convert Hexadecimal String to Decimal Integer.
import java.util.Scanner;
class HexStringToInt
{
public static void main(String args[])
{
String hex_value=null;
int int_value=0;
Scanner SC=new Scanner(System.in);
//read hex value
System.out.print("Enter value in hexadecimal: ");
hex_value=SC.next();
//converting it into integer
int_value=Integer.parseInt(hex_value.trim(), 16 );
//print values
System.out.println("Integer value of: " + hex_value + " is: " + int_value);
}
}
Output
Enter value in hexadecimal: 156AF
Integer value of: 156AF is: 87727