English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Program to Convert Decimal Integer to Hexadecimal Number

Using thistoHexString()The method converts decimal to hexadecimal. This method returns the string representation of the integer parameter (in16An unsigned integer in base 16. The following characters are used as hexadecimal digits: 0123456789abcdef.

Here is the syntax.

String toHexString(int i)

It has only one parameter.

  • i-This is an integer that needs to be converted to a string.

Example

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

Output Result

Decimal = 45
2d