Converts the specified integer into its hexadecimal string representation. The returned string is a concatenation of characters from '0' to '9' and 'a' to 'f'. @param i the integer to convert. @return the hexadecimal string representation of i.
(int i)
| 418 | * @return the hexadecimal string representation of {@code i}. |
| 419 | */ |
| 420 | public static String toHexString(int i) { |
| 421 | int count = 1, j = i; |
| 422 | |
| 423 | if (i < 0) { |
| 424 | count = 8; |
| 425 | } else { |
| 426 | while ((j >>>= 4) != 0) { |
| 427 | count++; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | char[] buffer = new char[count]; |
| 432 | do { |
| 433 | int t = i & 15; |
| 434 | if (t > 9) { |
| 435 | t = t - 10 + 'a'; |
| 436 | } else { |
| 437 | t += '0'; |
| 438 | } |
| 439 | buffer[--count] = (char) t; |
| 440 | i >>>= 4; |
| 441 | } while (count > 0); |
| 442 | return new String(0, buffer.length, buffer); |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Converts the specified integer into its octal string representation. The |