From 73bab98fa6620a7648927fbab9856dd7cb334726 Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期三, 27 十二月 2023 17:38:19 +0800
Subject: [PATCH] 2023-12-27 朱宝民 完善了几个功能
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java | 32 +++++++++++++++++++++++++++++++-
1 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
index c782aa6..ce00ba0 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
@@ -1027,6 +1027,34 @@
}
return new String(buf);
}
+ /**
+ * 灏哹yte[]杞崲涓�16杩涘埗瀛楃涓�
+ *
+ * @param bytes 寰呰浆鎹yte[]
+ * @return 杩斿洖 杞崲鍚庣殑瀛楃涓�
+ */
+ public static String bytesToHex(byte[] bytes, int startIndex, int endIndex) {
+ byte[] bs = new byte[endIndex - startIndex + 1] ;
+ byte j = 0 ;
+ for(int i = startIndex; i <= endIndex; i++){
+ bs[j++] = bytes[i] ;
+ }
+ //涓�涓猙yte涓�8浣嶏紝鍙敤涓や釜鍗佸叚杩涘埗浣嶆爣璇�
+ char[] buf = new char[bs.length * 2];
+ int a = 0;
+ int index = 0;
+ for (byte b : bs) { // 浣跨敤闄や笌鍙栦綑杩涜杞崲
+ if (b < 0) {
+ a = 256 + b;
+ } else {
+ a = b;
+ }
+
+ buf[index++] = HEX_CHAR[a / 16];
+ buf[index++] = HEX_CHAR[a % 16];
+ }
+ return new String(buf);
+ }
/**
* 灏�16杩涘埗瀛楃涓茶浆鎹负byte[]
@@ -1458,6 +1486,7 @@
// System.out.println(v5);
//
// }
+ /*
public static void main(String[] args) throws Exception {
byte[] bs = new byte[]{0x38, 0x36, 0x39, 0x31} ;
String s = bytes2String_BE(bs, 0, 3) ;
@@ -1471,5 +1500,6 @@
}
System.out.println(v);
}
-
+ */
+
}
--
Gitblit v1.8.0