Skip to content

Commit 00a29a9

Browse files
committed
字节数组转换二进制字符串
1 parent 4606b8a commit 00a29a9

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.springboot.demo.util;
2+
3+
/**
4+
* @author yanghao
5+
* @date 2019-07-04 15:14
6+
*/
7+
public class ByteUtil {
8+
9+
10+
private static String hexStr = "0123456789ABCDEF";
11+
private static String[] binaryArray =
12+
{
13+
"0000", "0001", "0010", "0011",
14+
"0100", "0101", "0110", "0111",
15+
"1000", "1001", "1010", "1011",
16+
"1100", "1101", "1110", "1111"
17+
};
18+
19+
20+
/**
21+
* 字节数组转换为二进制字符串
22+
*
23+
* @param bArray
24+
* @return
25+
*/
26+
public static String bytes2BinaryStr(byte[] bArray) {
27+
28+
String outStr = "";
29+
int pos = 0;
30+
for (byte b : bArray) {
31+
//高四位
32+
pos = (b & 0xF0) >> 4;
33+
outStr += binaryArray[pos];
34+
//低四位
35+
pos = b & 0x0F;
36+
outStr += binaryArray[pos];
37+
}
38+
return outStr;
39+
40+
}
41+
42+
43+
44+
45+
}

module-web/src/main/resources/application-prod.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ spring:
4545
mongodb:
4646
uri: mongodb://localhost:27017/springboot-demo
4747

48-
49-
5048
# email配置
5149
mail:
5250
host: smtp.qq.com

0 commit comments

Comments
 (0)