Java Integer - toHexString() Method
The java.lang.Integer.toHexString() method returns a string representation of the integer argument as an unsigned integer in base 16.
Syntax
public static String toHexString(int i)
Parameters
i |
Specify a integer to be converted to a string. |
Return Value
Returns the string representation of the unsigned integer value represented by the argument in hexadecimal (base 16).
Exception
NA.
Example:
In the example below, the java.lang.Integer.toHexString() method returns a string representation of the integer argument as an unsigned integer in base 16.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating int value int x = 25; int y = 31; int z = 111; //creating and printing string representation of //argument in hexadecimal system. System.out.println("x in hexadecimal system is: " + Integer.toHexString(x)); System.out.println("y in hexadecimal system is: " + Integer.toHexString(y)); System.out.println("z in hexadecimal system is: " + Integer.toHexString(z)); } }
The output of the above code will be:
x in hexadecimal system is: 19 y in hexadecimal system is: 1f z in hexadecimal system is: 6f
❮ Java.lang - Integer