1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| package Method;
| /**¸ÃÀàÓÃÓÚ½«×Ö½ÚÊý×éתΪ16½øÖÆÊä³ö*/
| public class BytesToHex {
| /**
| * byteÊý×é ת»»³É 16½øÖÆÐ¡Ð´×Ö·û´®
| */
| public static String bytes2Hex(byte[] bytes) {
| if (bytes == null || bytes.length == 0) {
| return null;
| }
|
| StringBuilder hex = new StringBuilder();
|
| for (byte b : bytes) {
| hex.append(HEXES[(b >> 4) & 0x0F]);
| hex.append(HEXES[b & 0x0F]);
| }
|
| return hex.toString();
| }
|
| private static final char[] HEXES = {
| '0', '1', '2', '3',
| '4', '5', '6', '7',
| '8', '9', 'a', 'b',
| 'c', 'd', 'e', 'f'
| };
| }
|
|