Decimal to Hexadecimal Java Program

Conversion programs in java are very common. Below is one such kind of conversion. Come let us learn decimal to hexadecimal java program.

Moving ahead, in number system decimal number has a base of ten.

It has digits from 0 to 9.

Whereas hexadecimal number has a base 16. It has digits from 0 to 9 and A to F.

Now let’s see the comparison through a table,

Decimal to Hexadecimal Java Program

As you can see in the above table, from 0 to 9 the numbers are same in both number system.

Then after 10, 10 is denoted as ‘A’, 11 is denoted as ‘B’, 12 is denoted as ‘C’, 13 is denoted as ‘D’, 14 is denoted as ‘E’, 15 is denoted as ‘F’ in the hexadecimal system.

In the previous post we saw how to convert binary to decimal and decimal to binary java program.

In this program Scanner class is used.  String java.lang.Integer.toHexString(int i) is used to convert decimal value to hexadecimal format.

So, let’s get into example,

Example: Decimal to Hexadecimal Java Program

import java.util.Scanner;

public class Decimal_to_Hex {

int number;
Scanner sc;

void get_Val(){
System.out.println("Conversion from Decimal to Hexadecimal" );
sc = new Scanner(;
System.out.println("Please enter Decimal Number: ");
number = Integer.parseInt(sc.nextLine());

void to_Convert(){
String hex = Integer.toHexString(number);
System.out.println("The converted Hexadecimal value is: " + hex);

public static void main(String[] args) {

Decimal_to_Hex dth = new Decimal_to_Hex();


Decimal to Hexadecimal Java Program

About the author


View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *