From 182b4da079c0a8011fec33cb5908a1d43adcbcd7 Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期五, 31 三月 2023 09:19:42 +0800
Subject: [PATCH] 默认变更列表

---
 src/main/java/com/boying/util/StringUtil.java |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/boying/util/StringUtil.java b/src/main/java/com/boying/util/StringUtil.java
index ce93eb1..2075beb 100644
--- a/src/main/java/com/boying/util/StringUtil.java
+++ b/src/main/java/com/boying/util/StringUtil.java
@@ -1,5 +1,6 @@
 package com.boying.util;
 
+import java.util.Arrays;
 import java.util.UUID;
 
 public class StringUtil {
@@ -11,8 +12,104 @@
         }
         return false;
     }
+    public static byte[] convertNum(String s){
+        String[] split = s.split("-");
+        byte[] bytes = new byte[split.length];
+        for (int i = 0; i < split.length; i++) {
+            String s1 = split[i];
+            byte b = Byte.parseByte("0x"+s1);
+            bytes[i]=b;
+        }
+        return bytes;
+    }
+
+    public static String toStr(String[] strs){
+        String s = Arrays.toString(strs);
+        String substring = s.substring(1, s.length() - 1);
+        String s1 = substring.replaceAll(",", "");
+        String s2 = s1.replaceAll(" ", "");
+        return s2;
+    }
 
     public static String getUUID() {
         return UUID.randomUUID().toString().replaceAll("-", "");
     }
+
+    /**
+     * 灏嗘寚瀹歜yte鏁扮粍浠�16杩涘埗鐨勫舰寮忔墦鍗板埌鎺у埗鍙�
+     *
+     * @param hint String
+     * @param b    byte[]
+     * @return void
+     */
+    public static void printHexString(String hint, byte[] b) {
+        System.out.print(hint);
+        for (int i = 0; i < b.length; i++) {
+            String hex = Integer.toHexString(b[i] & 0xFF);
+            if (hex.length() == 1) {
+                hex = '0' + hex;
+            }
+            System.out.print(hex.toUpperCase() + " ");
+        }
+    }
+
+    /**
+     * @param b byte[]
+     * @return String
+     */
+    public static String Bytes2HexString(byte[] b) {
+        String ret = "";
+        for (int i = 0; i < b.length; i++) {
+            String hex = Integer.toHexString(b[i] & 0xFF);
+            if (hex.length() == 1) {
+                hex = '0' + hex;
+            }
+            ret += " 0x" + hex.toUpperCase();
+        }
+        return ret;
+    }
+
+    /**
+     * 灏嗘寚瀹氬瓧绗︿覆src锛屼互姣忎袱涓瓧绗﹀垎鍓茶浆鎹负16杩涘埗褰㈠紡 濡傦細"2B44EFD9" 鈥�> byte[]{0x2B, 0脳44, 0xEF,
+     * 0xD9}
+     *
+     * @param src String
+     * @return byte[]
+     */
+    public static byte[] HexString2Bytes(String src) {
+        if (null == src || 0 == src.length()) {
+            return null;
+        }
+        String s1 = src.replaceAll("-", "");
+        byte[] ret = new byte[s1.length() / 2];
+        byte[] tmp = s1.getBytes();
+        for (int i = 0; i < (tmp.length / 2); i++) {
+            ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]);
+        }
+        return ret;
+    }
+
+    /**
+     * 灏嗕袱涓狝SCII瀛楃鍚堟垚涓�涓瓧鑺傦紱 濡傦細"EF"鈥�> 0xEF
+     *
+     * @param src0 byte
+     * @param src1 byte
+     * @return byte
+     */
+    public static byte uniteBytes(byte src0, byte src1) {
+        byte _b0 = Byte.decode("0x" + new String(new byte[]{src0})).byteValue();
+        _b0 = (byte) (_b0 << 4);
+        byte _b1 = Byte.decode("0x" + new String(new byte[]{src1})).byteValue();
+        byte ret = (byte) (_b0 ^ _b1);
+        return ret;
+    }
+
+    public static void main(String[] args) {
+        String s = "00-64-FF-FF-6E-78-00-04-00-01-01-02-00-FF-00-00-00-09-E4-BA-AC-41-38-38-38-38-38-0D-01-01-01-02-00-FF-00-00-00-09-E4-B8-B4-E6-97-B6-E8-BD-A6-0D-02-01-01-02-00-FF-00-00-00-0C-E6-AC-A2-E8-BF-8E-E5-85-89-E4-B8-B4-0D-03-01-01-02-00-FF-00-00-00-09-E4-BD-99-E4-BD-8D-3A-37-34-00-0A-20-E4-B8-B4-E6-97-B6-E8-BD-A6-2C-E4-BA-AC-41-38-38-38-38-38-2C-E6-AC-A2-E8-BF-8E-E5-85-89-E4-B8-B4-00-6B-E7";
+        String s1 = s.replaceAll("-", "");
+        byte[] bytes = HexString2Bytes(s1);
+        for (byte aByte : bytes) {
+            System.out.print(aByte + " ");
+        }
+    }
 }

--
Gitblit v1.9.1