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) { public static byte calcCrc8_E5(byte[] data) {
byte crc = 0; byte crc = 0;
for (int j = 0; j < data.length; j++) { for (byte datum : data) {
crc ^= data[j]; crc ^= datum;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if ((crc & 0x80) != 0) { if ((crc & 0x80) != 0) {
crc = (byte) ((crc) << 1); crc = (byte) ((crc) << 1);
crc ^= 0xE5; crc ^= (byte) 0xE5;
} else { } else {
crc = (byte) ((crc) << 1); crc = (byte) ((crc) << 1);
} }

View File

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