Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Convert Decimal Integer to Hexadecimal Number in Java



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
Updated on: 2020-06-26T10:41:08+05:30

357 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements