Convert decimal integer to hexadecimal number in Java


To convert decimal integer to hexadecimal, use the Integer.toHexString() method. Let’s say the following is our decimal integer.

int decInt = 25;

The following is the usage of the Integer.toHexString() method to convert decimal integer to hexadecimal number.

String myHex = Integer.toHexString(decInt);

The following the complete example.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      int decInt = 25;
      System.out.println("Decimal Integer = "+decInt);
      String myHex = Integer.toHexString(decInt);
      System.out.println("Hexadecimal = "+myHex);
   }
}

Output

Decimal Integer = 25
Hexadecimal = 19

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

241 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements