liurunyu
2023-11-27 bd946b3758c86dab28f044c0a411adca2c0b55f9
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
@@ -1027,6 +1027,34 @@
      }
      return new String(buf);
   }
   /**
    * 将byte[]转换为16进制字符串
    *
    * @param bytes 待转换byte[]
    * @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] ;
      }
      //一个byte为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);
   }
   */
   
}