update 远程更新

This commit is contained in:
Guoqs
2024-05-23 16:41:20 +08:00
parent 4a79159f35
commit 853db78efb
2 changed files with 60 additions and 42 deletions

View File

@@ -516,37 +516,6 @@ public class BytesUtil {
return result;
}
public static void main(String[] args) {
// byte[] a = new byte[] {0x0C, 0x00, 0x00, 0x00, 0x02, 0x20, 0x22, 0x12, 0x14, 0x00, 0x00, 0x01, 0x00};
// byte[] bytes = intToBytes(CRC16Util.calcCrc16(a));
// String binary = binary(bytes, 16);
// System.out.println(binary);
// String a = "10";
// byte[] bytes = bigDecimal2Bcd(new BigDecimal(a));
//
// System.out.println(bytes);
// byte[] startTimeByteArr = new byte[] {(byte) 0x98, (byte) 0xB7, 0x0E, 0x11, 0x10, 0x03, 0x14};
// String binary = binary(startTimeByteArr, 16);
// String s = DateUtils.decodeCP56Time2a(binary);
// System.out.println(s);
byte[] a = new byte[] {0x33, 0x37, 0x31, 0x31, 0x30, 0x30, 0x41, 0x4E, 0x38, 0x42, 0x53, 0x33, 0x43, 0x47, 0x38, 0x36, 0x4C};
String s = ascii2Str(a);
System.out.println(s);
String s1 = ascii2StrLittle(a);
System.out.println(s1);
// BigDecimal chargeAmount = new BigDecimal("10.5").setScale(2, BigDecimal.ROUND_HALF_UP);
// byte[] accountBalanceByteArr = BytesUtil.getFloatBytes(chargeAmount.floatValue());
//
// float aFloat = BytesUtil.getFloat(accountBalanceByteArr);
//
// System.out.println(aFloat);
}
/**
* @param hexString
* @return 将十六进制转换为二进制字节数组 16-2
@@ -601,7 +570,7 @@ public class BytesUtil {
*/
public static byte[] checkLengthAndBehindAppendZero(byte[] msg, int length) {
String s = BytesUtil.binary(msg, 16);
int msgLen = msg.length;
int msgLen = s.length();
if (msgLen < length) {
while (msgLen < length) {
StringBuffer sb = new StringBuffer();
@@ -609,7 +578,7 @@ public class BytesUtil {
sb.append(s).append("0");
s = sb.toString();
msgLen = s.length();
}
}
} else {
return msg;
}
@@ -639,6 +608,57 @@ public class BytesUtil {
return BytesUtil.str2Bcd(s);
}
/**
* 确保byte数组长度至少为指定长度不足则在末尾补充0。
*
* @param bytes 原始byte数组
* @param length 指定的最小长度
* @return 补充0后确保长度至少为指定长度的byte数组
*/
public static byte[] ensureLength(byte[] bytes, int length) {
if (bytes.length < length) {
// 创建一个新的byte数组长度为指定长度前面填充原数组的元素后面补充0
byte[] newArray = new byte[length];
System.arraycopy(bytes, 0, newArray, 0, bytes.length);
return newArray;
}
// 如果原数组长度已经达到或超过指定长度,则直接返回原数组
return bytes;
}
public static void main(String[] args) {
byte[] originalBytes = {1, 2, 3};
int desiredLength = 5;
byte[] result = ensureLengthPrependZero(originalBytes, desiredLength);
System.out.println("Original array: ");
for (byte b : originalBytes) {
System.out.print(b + " ");
}
System.out.println("\nResulting array with padding at the beginning: ");
for (byte b : result) {
System.out.print(b + " ");
}
}
/**
* 确保byte数组长度至少为指定长度不足则在前面补充0。
*
* @param bytes 原始byte数组
* @param length 指定的最小长度
* @return 补充0后确保长度至少为指定长度的byte数组不足部分在前面补充
*/
public static byte[] ensureLengthPrependZero(byte[] bytes, int length) {
if (bytes.length < length) {
// 创建一个新的byte数组长度为指定长度前面补充0后面放置原数组的元素
byte[] newArray = new byte[length];
System.arraycopy(bytes, 0, newArray, length - bytes.length, bytes.length);
return newArray;
}
// 如果原数组长度已经达到或超过指定长度,则直接返回原数组
return bytes;
}
/**
* 将金额转换成BCD数组
*