wjc
2025-04-09 87cd5df70918e6ba1af849c5f026d3719bfdb1ac
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
32
33
34
35
36
37
38
39
40
41
42
package com.hdl.sdk.link.core.utils;
 
/**
 * Created by hxb on 2022/8/5.
 */
public class ByteUtils {
 
    public static String encodeHexString(byte[] data) {
 
        StringBuilder sb = new StringBuilder();
 
        for (byte b : data) {
            String hex = Integer.toHexString(0xFF & b);
            if (hex.length() == 1) {
                sb.append('0');
            }
            sb.append(hex).append(' ');
        }
        return sb.toString();
 
    }
 
    public static String encodeHexString(byte b) {
        return String.format("%02x ", b);
    }
 
 
    /**
     * byte转int
     */
    public static int ByteToInt(byte value) {
        return 0xFF & value;
    }
 
    public static int ByteToInt(byte []value) {
        return ByteToInt(value[0]) * 256 + ByteToInt(value[1]);
    }
 
    public static byte[] IntToByte(int value) {
        return new byte[]{(byte) (value / 256), (byte) (value % 256)};
    }
}