In  this tutorial, we will see “How to convert Hexadecimal to Decimal in Java?”

How to convert hexadecimal number to decimal in java

Java – How to convert Hexadecimal to Decimal number? Share on X

/**
 * Using Java, Convert Hexadecimal Number to Decimal
 * @author Deepak Verma
 *
 */

import java.util.Scanner;

public class Convert_Hexadecimal_to_Decimal_Java_Example {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			System.out.print("Enter a Hexadecimal number: ");

			String hexadecimalNumber = sc.nextLine();

			int decimalNumber = Integer.parseInt(hexadecimalNumber, 16);

			System.out.println("Decimal counterpart: " + decimalNumber);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
	}
}

 

Output:

Enter a Hexadecimal number: 1af
Decimal counterpart: 431

How to convert hexadecimal number to decimal in java

Java – How to convert Hexadecimal to Decimal number? Share on X

Do you like this Post? – then check my other helpful posts:

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester.

    He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    View all posts