Convert hexadecimal string to decimal integer in Java

The program below converts a hexadecimal value to its equivalent in integer. It uses the Integer.parseInt() function to convert from hexadecimal, which is included in the Scanner namespace.

Convert Hexadecimal string to an integer using Java

import java.util.Scanner;
class ConvertHexToInt
    public static void main(String args[])
        String hexValue = null;
        int result = 0;
        Scanner scanner = new Scanner(;
        System.out.print("Please enter a hexadecimal value: ");
        hexValue =;
        result = Integer.parseInt(hexValue.trim(), 16 );
        System.out.println("The integer value of " + hexValue + " is " + result);


Please enter a hexadecimal value: DDEE
The integer value of DDEE is 56814

One Reply to “Convert hexadecimal string to decimal integer in Java”

Comments are closed.