From 8efb5a8cd2c8a6b40e58f4f3fb851d54cf415af9 Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期日, 24 十二月 2023 01:23:55 +0800
Subject: [PATCH] 游仙协议解析-1

---
 src/main/java/com/fzzy/api/utils/BytesUtil.java |   92 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/src/main/java/com/fzzy/api/utils/BytesUtil.java b/src/main/java/com/fzzy/api/utils/BytesUtil.java
index af40a1d..af4348e 100644
--- a/src/main/java/com/fzzy/api/utils/BytesUtil.java
+++ b/src/main/java/com/fzzy/api/utils/BytesUtil.java
@@ -320,29 +320,6 @@
 		return String.format("%04x", num).toUpperCase();
 	}
 
-	// 璁$畻16杩涘埗瀵瑰簲鐨勬暟鍊�
-	public static int GetHex(char ch) throws Exception {
-		if (ch >= '0' && ch <= '9')
-			return (int) (ch - '0');
-		if (ch >= 'a' && ch <= 'f')
-			return (int) (ch - 'a' + 10);
-		if (ch >= 'A' && ch <= 'F')
-			return (int) (ch - 'A' + 10);
-		throw new Exception("error param");
-	}
-
-	// 璁$畻骞�
-	public static int GetPower(int nValue, int nCount) throws Exception {
-		if (nCount < 0)
-			throw new Exception("nCount can't small than 1!");
-		if (nCount == 0)
-			return 1;
-		int nSum = 1;
-		for (int i = 0; i < nCount; ++i) {
-			nSum = nSum * nValue;
-		}
-		return nSum;
-	}
 
 	public static void main(String[] args) {
 		
@@ -353,6 +330,7 @@
 		System.out.println(d2);
 		
 		System.out.println(d1 + d2);
+
 		
 	}
 
@@ -401,4 +379,72 @@
 	public static String folatToHexString(Float value) {
 		return Integer.toHexString(Float.floatToIntBits(value));
 	}
+
+	/**
+	 * int杞�16杩涘埗瀛楃涓� 1浣嶇疆 00
+	 *
+	 * @param num
+	 * @return
+	 */
+	public static String intToHexStr1(int num) {
+		// 闇�瑕佷娇鐢�2瀛楄妭琛ㄧずb
+		return String.format("%02x", num).toUpperCase();
+	}
+
+	public static String hexString2binaryString(String hexString, int num) {
+		//16杩涘埗杞�10杩涘埗
+		BigInteger sint = new BigInteger(hexString, num);
+		//10杩涘埗杞�2杩涘埗
+		String str = sint.toString(2);
+		if(str.length() < num){
+			for (int i = str.length(); i < num; i++) {
+				str = "0" + str;
+			}
+		}
+		return str;
+	}
+
+	/**
+	 * 灏嗕簩杩涘埗杞崲涓�10杩涘埗
+	 * @param binStr
+	 * @return
+	 */
+	public  static  Integer biannary2Decimal(String binStr){
+
+		Integer sum = 0;
+		int len = binStr.length();
+
+		for (int i=1;i<=len;i++){
+			//绗琲浣� 鐨勬暟瀛椾负锛�
+			int dt = Integer.parseInt(binStr.substring(i-1,i));
+			sum+=(int)Math.pow(2,len-i)*dt;
+		}
+		return  sum;
+	}
+
+	/**
+	 * 浜岃繘鍒惰ˉ鐮侊細鍙栧弽鍙e姞1
+	 * @param str
+	 * @return
+	 */
+	public static Integer twoToString(String str) {
+		String two = "";
+		String[] split = str.split("");
+		for (int i = 0;i< split.length;i++){
+			if("1".equals(split[i])){
+				two += "0";
+			}else if("0".equals(split[i])){
+				two += "1";
+			}
+		}
+		return biannary2Decimal(two) + 1;
+	}
+
+	public static String byteToHex(byte b) {
+		String hex = Integer.toHexString(b & 0xFF);
+		if (hex.length() < 2) {
+			hex = "0" + hex;
+		}
+		return hex;
+	}
 }

--
Gitblit v1.9.3