From 52952d6feed8a9df738c652cda6c7d1ca50d2921 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 23 十一月 2023 17:20:23 +0800
Subject: [PATCH] 1、修改rtuAddr注释 2、实现开关阀自报协议 3、实现开阀工作报 4、《编码设计》
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 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..7f561f1 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[]
--
Gitblit v1.8.0