android ble setValue 是 0x00010000

android ble setValue is 0x00010000

我只有一个功能:

public static String toPaddedHex(int i) {
    return String.format("0x%04X", i);
}

//print

System.out.println(toPaddedHex(1));  // 0x0001

如果我要打印是“0x00010000” 我该怎么办?

试试这个代码:

public static String toPaddedHex(int i,int shift) {
    return String.format("0x%8s", Integer.toBinaryString(i<<shift)).replace(' ', '0')
}

Demo