From 742e0a8ec019ccb76f03fcc58859ed15e9264c4c Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期三, 31 一月 2024 08:26:30 +0800
Subject: [PATCH] 2024-01-31 朱宝民 电子钱包账户注册接口、充值接口
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java | 64 +++++++++----------------------
1 files changed, 19 insertions(+), 45 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 7f561f1..7fe22e9 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
@@ -33,9 +33,8 @@
* @param index 涓嬫爣浣�
* @param len 闀垮害
* @return 杩斿洖 杩斿洖
- * @throws Exception 寮傚父
*/
- public static boolean bytesIsAll0xFF(byte[] bs, int index, int len)throws Exception {
+ public static boolean bytesIsAll0xFF(byte[] bs, int index, int len){
int count = 0 ;
for(int i = index; i < index + len; i++){
if(bs[i] == (byte)0xFF){
@@ -47,26 +46,11 @@
/**
* 浜岃繘鍒惰浆鍗佽繘鍒舵暟
- * @param str
+ * @param str 浜岃繘鍒跺瓧绗︿覆
* @return 杩斿洖
- * @throws Exception 寮傚父
*/
- public static int binary2Int(String str) throws Exception {
- int cnt=0;
- int sum=0;
- str=new StringBuilder(str).reverse().toString();//鍙嶈浆瀛楃涓�
- for(int i=0;i<str.length();i++){
- cnt++;
- if (str.charAt(i)=='1'){
- int mul=1;
- for (int j=1;j<cnt;j++){
- mul*=2;
- }
- sum+=mul;
- }
- else continue;
- }
- return sum;
+ public static int binary2Int(String str) {
+ return Integer.parseInt(str, 2);
}
@@ -74,26 +58,18 @@
* 瀛楄妭杞瓨浜岃繘鍒�
*
* @param b byte
- * @throws Exception 寮傚父
* @return 杩斿洖 String
*/
- public static String byte2Binary(byte b) throws Exception {
- int n = (b + 256) % 256 + 256;
- try {
- return Integer.toBinaryString(n).substring(1);
- } catch (Exception e) {
- throw new Exception("瀛楄妭杞崲鎴愪簩杩涘埗鐨勫瓧绗︿覆鍑洪敊锛�", null);
- }
+ public static String byte2Binary(byte b) {
+ return Integer.toBinaryString(b & 0xFF) ;
}
/**
* 瀛楄妭杞瓨8浣嶄簩杩涘埗
*
- * @param b
- * byte
- * @throws Exception 寮傚父
+ * @param b byte
* @return 杩斿洖 String
*/
- public static String byte2bit8Binary(byte b) throws Exception {
+ public static String byte2bit8Binary(byte b) {
String s = byte2Binary(b);
int len = s.length();
for (int i = 0; i < 8 - len; i++) {
@@ -103,13 +79,11 @@
}
/**
- * 瀛楄妭鍙朾it
- * @param b
- * @param b
- * @throws Exception 寮傚父
+ * 瀛楄妭鏁� 鍙栧嚭8涓猙it
+ * @param b 瀛楄妭鏁�
* @return 杩斿洖 String
*/
- public static byte[] getBit(byte b) throws Exception {
+ public static byte[] getBit(byte b) {
byte[] bs = new byte[8] ;
bs[0] = (byte)(b & 1) ;
bs[1] = (byte)((b & 2) >> 1) ;
@@ -123,8 +97,8 @@
}
/**
- * 瀛楄妭鍙朾it
- * @param b
+ * 瀛楄妭鏁� 鍙栧嚭bit
+ * @param b 瀛楄妭鏁�
* @param index 涓嬫爣浣�
* @throws Exception 寮傚父
* @return 杩斿洖 String
@@ -178,8 +152,7 @@
public static void double2Bytes_BE(byte[] bs, double value, int from)throws Exception {
boolean b = isOutOfArrLength(bs.length, (from - 1) + 8);
if (b) {
- Long l = Double.doubleToLongBits(value);
- long2Bytes_BE(bs, l, from);
+ long2Bytes_BE(bs, Double.doubleToLongBits(value), from);
} else {
throw new Exception("double2Bytes鏃舵暟缁勮秺鐣�");
}
@@ -195,8 +168,7 @@
public static void double2Bytes_LE(byte[] bs, double value, int from)throws Exception {
boolean b = isOutOfArrLength(bs.length, (from - 1) + 8);
if (b) {
- Long l = Double.doubleToLongBits(value);
- long2Bytes_LE(bs, l, from);
+ long2Bytes_LE(bs, Double.doubleToLongBits(value), from);
} else {
throw new Exception("double2Bytes鏃舵暟缁勮秺鐣�");
}
@@ -452,7 +424,7 @@
boolean b = isOutOfArrLength(bs.length, (from - 1) + 8);
if (b) {
long s = 0;
- long s0 = bs[from + 0] ;// 鏈�浣庝綅
+ long s0 = bs[from] ;// 鏈�浣庝綅
long s1 = bs[from + 1] ;
long s2 = bs[from + 2] ;
long s3 = bs[from + 3] ;
@@ -1486,6 +1458,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) ;
@@ -1499,5 +1472,6 @@
}
System.out.println(v);
}
-
+ */
+
}
--
Gitblit v1.8.0