Skip to Content

Convert decimal integer to hexadecimal number example

  1. /*
  2.         Convert decimal integer to hexadecimal number example.
  3.         This example shows how to convert int to hexadecimal number using
  4.         toHexString method of Integer wrapper class.
  5. */
  6.  
  7. public class ConvertIntToHexExample {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 int i = 32;
  12.                
  13.                 String strHexNumber = Integer.toHexString(i);
  14.                
  15.                 System.out.println("Convert decimal number to hexadecimal number example");
  16.                 System.out.println("Hexadecimal value of " + i + " is " + strHexNumber);
  17.                                                        
  18.         }
  19. }
  20.  
  21. /*
  22. Output would be
  23. Convert decimal number to hexadecimal number example
  24. Hexadecimal value of 32 is 20
  25. */