This commit is contained in:
zhugongping 2026-09-19 04:40:48 +08:00
parent 0cc08a8c5c
commit 3ef98ab448
2 changed files with 7 additions and 7 deletions

View File

@ -25,12 +25,12 @@ public class CRC8Utils {
*/
public static byte calcCrc8_E5(byte[] data) {
byte crc = 0;
for (int j = 0; j < data.length; j++) {
crc ^= data[j];
for (byte datum : data) {
crc ^= datum;
for (int i = 0; i < 8; i++) {
if ((crc & 0x80) != 0) {
crc = (byte) ((crc) << 1);
crc ^= 0xE5;
crc ^= (byte) 0xE5;
} else {
crc = (byte) ((crc) << 1);
}

View File

@ -78,8 +78,7 @@ public class ByteUtils {
byte[] write = new byte[length];
int index = 0;
for (int i = 0; i < bytes.size(); i++) {
byte[] values = bytes.get(i);
for (byte[] values : bytes) {
addBytes(write, values, index);
index += values.length;
}
@ -312,7 +311,8 @@ public class ByteUtils {
if (StringUtils.isBlank(hexStr)) {
return null;
}
if (hexStr.length() % 2 != 0) {//长度为单数
// 长度为单数
if (hexStr.length() % 2 != 0) {
hexStr = "0" + hexStr; // 前面补0
}