Java Program to convert decimal integer to hexadecimal number


Use the toHexString() method to convert decimal to hexadecimal. The method returns a string representation of the integer argument as an unsigned integer in base 16. The following characters are used as hexadecimal digits:0123456789abcdef.

The following is the syntax.

String toHexString(int i)

It has only single parameter.

  • i − This is an integer to be converted to a string.

Example

 Live Demo

public class Demo {
   public static void main( String args[] ) {
      int dec = 45;
      System.out.println("Decimal = "+dec);
      // converting to hex
      System.out.println(Integer.toHexString(dec));
   }
}

Output

Decimal = 45
2d

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

246 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements