Java Program to convert decimal integer to hexadecimal number

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 13-Nov-2018 11:50:28
Advertisements