Commit 04b6fa6f authored by zengtianlai3's avatar zengtianlai3

2.3.6 代码质量:循环中拼接字符串

parent 8e4794fb
...@@ -4,13 +4,13 @@ public class HexUtil { ...@@ -4,13 +4,13 @@ public class HexUtil {
public static String bytes2hex(byte[] bytes) { public static String bytes2hex(byte[] bytes) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String tmp; StringBuilder tmp;
sb.append("["); sb.append("[");
for (byte b : bytes) { for (byte b : bytes) {
// 将每个字节与0xFF进行与运算,然后转化为10进制,然后借助于Integer再转化为16进制 // 将每个字节与0xFF进行与运算,然后转化为10进制,然后借助于Integer再转化为16进制
tmp = Integer.toHexString(0xFF & b); tmp = new StringBuilder(Integer.toHexString(0xFF & b));
if (tmp.length() == 1) { if (tmp.length() == 1) {
tmp = "0" + tmp;//只有一位的前面补个0 tmp = tmp.insert(0, '0');//只有一位的前面补个0
} }
sb.append(tmp).append(" ");//每个字节用空格断开 sb.append(tmp).append(" ");//每个字节用空格断开
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment