fix
This commit is contained in:
parent
0cc08a8c5c
commit
3ef98ab448
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,8 +311,9 @@ public class ByteUtils {
|
|||||||
if (StringUtils.isBlank(hexStr)) {
|
if (StringUtils.isBlank(hexStr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (hexStr.length() % 2 != 0) {//长度为单数
|
// 长度为单数
|
||||||
hexStr = "0" + hexStr;//前面补0
|
if (hexStr.length() % 2 != 0) {
|
||||||
|
hexStr = "0" + hexStr; // 前面补0
|
||||||
}
|
}
|
||||||
|
|
||||||
char[] chars = hexStr.toCharArray();
|
char[] chars = hexStr.toCharArray();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user