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

How to convert decimal number to hexadecimal in java

Java – How to convert Decimal number to Hexa-Decimal? Share on X

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

import java.util.Scanner;

public class Convert_Decimal_Number_To_Hexadecimal_Java_Example {

	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in)) {
			
			System.out.print("Enter a Decimal Number: ");
		
			int decimalNumber = sc.nextInt();
			
			String hexadecimalNumber = Integer.toHexString(decimalNumber);
			
			System.out.println("Hexa-decimal representation of " + decimalNumber + " is: " + hexadecimalNumber);
		
		}
	}
}

 

Output:

Enter a decimal number: 23
Hexadecimal representation of 23 is: 17

How to convert decimal number to hexadecimal in java

In the above example, It uses Integer.toHexString() method, which is a built-in method in Java to convert decimal number to a hexadecimal counterpart.

Java – How to convert Decimal number to Hexa-Decimal? 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