-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.java
More file actions
35 lines (29 loc) · 1014 Bytes
/
Copy pathUtils.java
File metadata and controls
35 lines (29 loc) · 1014 Bytes
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
class Utils {
static String convertByteArrayToHexString(byte[] arr) {
StringBuilder sb = new StringBuilder();
for (byte b : arr) {
sb.append(String.format("%02X ", b));
}
return sb.toString().trim();
}
static String[] convertByteArrayToHexStringArray(byte[] arr) {
return convertByteArrayToHexString(arr).split("\\s+");
}
static byte[] convertHexStringToByteArray(String s) {
s = s.replaceAll("\\s","");
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
}
return data;
}
static String convertByteArrayToUnsignedString(byte[] arr) {
StringBuilder sb = new StringBuilder();
for (byte b : arr) {
int n = b & 0xFF;
sb.append(n).append(" ");
}
return sb.toString();
}
}