533
Java Integer toHexString() Method
The toHexString() method of Java Integer class returns a string representation of the integer argument as an unsigned integer in hexadecimal base 16.
The following characters are used as hexadecimal digits:
Note: If the argument is negative, the unsigned integer value is the argument plus 232 otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in hexadecimal (base 16) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character ‘0’ otherwise, the first character representation of the unsigned magnitude will not be the zero character.
Explanation:
Decimal Number | Operation (%) | Quotient | Remainder | HexaDecimal Result |
---|---|---|---|---|
975 | 16 | 60 | 15 | F |
60 | 16 | 3 | 12 | CF |
3 | 16 | 0 | 3 | 3CF |
Hence:
Syntax:
Following is the declaration of toHexString () method:
Parameter:
DataType | Parameter | Description | Required/Optional |
---|---|---|---|
int | i | It specifies the integer number to be converted in hexadecimal format | Required |
Returns:
The toHexString() method returns the string representation of the unsigned integer value represented by the argument in hexadecimal (base 16).
Exceptions:
NA
Compatibility Version:
Java 1.0.2 and above
Example 1
Output:
Number = 975 HexaDecimal representation is = 3CF
Example 2
Output:
Enter the Number = 735 Number = 735 HexaDecimal representation is = 2df
Example 3
Output:
fa ffffff06 41a fffffbe6
Next TopictoOctalString() Method