Tuesday, March 17, 2015

Lesson 51: convert dec to hex (integer)

This is example is taken from http://www.tutorialspoint.com/java/lang/integer_tohexstring.htm

for example number 170 (dec) if you want to convert to hex it will be AA (hex)
you can use Integer.toHexString(int)

public static void main(String[] args) {

     int i = 170;
     System.out.println("Number = " + i);
    
     /* returns the string representation of the unsigned integer value
     represented by the argument in hexadecimal (base 16) */
     System.out.println("Hex = " + Integer.toHexString(i));
   }  


No comments:

Post a Comment