yy1717
2024-02-28 27fc91fbe8f88b6885356e68828cfe1ce1db7601
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 com.anyun.exam.lib.util;
 
public class ByteUtil {
    public static String byte2hex(byte [] buffer){
        StringBuilder h = new StringBuilder();
        for(int i = 0; i < buffer.length; i++){
            String temp = Integer.toHexString(buffer[i] & 0xFF).toUpperCase();
            if(temp.length() == 1){
                temp = "0" + temp;
            }
            h.append(temp);
            h.append(" ");
        }
        return h.toString();
    }
 
    public static String byte2hex(byte [] buffer, int length) {
        byte [] temp = new byte[length];
        System.arraycopy(buffer, 0, temp, 0, length);
        return byte2hex(temp);
    }
 
    public static boolean allIsAscii(byte []buffer) {
        for (int i = 0; i < buffer.length; i++) {
            if (buffer[i] < 0x20 || buffer[i] >= 0x7F) {
                return false;
            }
        }
        return true;
    }
}