KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > format > FormatUtil


1 package jodd.format;
2
3
4
5 /**
6  * Utility methods regarding formatting.
7  */

8 public final class FormatUtil {
9
10     private static char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
11
12     /**
13      * Returns a hex string representation of a 8 bit integer.
14      * Very fast. Returned hex values are in uppercase.
15      *
16      * @param b byte to convert to hex string
17      *
18      * @return hex value
19      */

20     public static String toHexString(int b) {
21         char[] digits = new char[2];
22         b = b & 255;
23
24         digits[0] = hexDigits[b / 0x10];
25         digits[1] = hexDigits[b % 0x10];
26
27         return new String(digits);
28     }
29 }
Popular Tags