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.in);
 
        System.out.print("Please enter a hexadecimal value: ");
        hexValue = scanner.next();
 
        result = Integer.parseInt(hexValue.trim(), 16 );
  
        System.out.println("The integer value of " + hexValue + " is " + result);
        
    }
}

Output

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

Last modified: November 5, 2020

Author

Comments

Write a Reply or Comment

Your email address will not be published.