每个字节转成16进制,方法1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
/** * 每个字节转成16进制,方法1 * * @param result */ private static String toHex( byte [] result) { StringBuffer sb = new StringBuffer(result.length * 2 ); for ( int i = 0 ; i < result.length; i++) { sb.append(Character.forDigit((result[i] & 240 ) >> 4 , 16 )); sb.append(Character.forDigit(result[i] & 15 , 16 )); } return sb.toString(); } |
每个字节转成16进制,方法2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
/** * 每个字节转成16进制,方法2 * * @param result * @return */ private static String toHex2( byte [] result) { StringBuffer sb = new StringBuffer(result.length * 2 ); for ( int i = 0 ; i < result.length; i++) { int hight = ((result[i] >> 4 ) & 0x0f ); int low = result[i] & 0x0f ; sb.append(hight > 9 ? ( char ) ((hight - 10 ) + 'a' ) : ( char ) (hight + '0' )); sb.append(low > 9 ? ( char ) ((low - 10 ) + 'a' ) : ( char ) (low + '0' )); } return sb.toString(); } |
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
原文链接:http://blog.csdn.net/johnny901114/article/details/11539833