liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
29
30
31
package framework.util;
 
public class BitUtil {
    public static String toHexString(int i){
        String s = Integer.toHexString(0x000000ff & i);
        s = s.trim().toUpperCase();
        if(s.length()==1){
            s = "0"+s;
        }
        
        return s;
    }
    
    public static int byte2Int(byte b){
        return 0x000000ff & b;
    }
    
    /**
     * 转成16进制字符串
     * @param bs
     * @return
     */
    public static String toHexString(byte[] bs){
        StringBuffer s = new StringBuffer("");
        for(byte b : bs){
            s.append(" ").append(BitUtil.toHexString(BitUtil.byte2Int(b)));
        }
 
        return s.toString().trim();
    }
}