2021与蓝度共同重构项目,服务端
chenjiantian
2021-12-06 295411fed71f1ea1286316ccc395d28cc5743fa8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.sandu.ximon.admin.manager.iot.rrpc.util;
 
/**
 * @author chenjiantian
 */
public class SupplementUtils {
 
 
    /**
     * 截取指定长度的字符串,不足以0填充前面
     * @param hex 字符串
     * @param totalBit 截取长度
     * @return 截取后的字符串
     */
    public static String suppleZero(String hex, Integer totalBit) {
 
        if (hex.length() > totalBit) {
            return hex.substring(0, totalBit);
        } else if (hex.length() == totalBit) {
            return hex;
        }
        totalBit = totalBit - hex.length();
 
        StringBuilder hexBuilder = new StringBuilder(hex);
        for (int i = 0; i < totalBit; i++) {
            hexBuilder.insert(0, "0");
        }
        hex = hexBuilder.toString();
        return hex;
    }
 
 
}