16位无符号数(unsigned short)转10进制://信号强度采用16位无符号数(unsigned short),数值越大信号越强, 单位db
0x00,0x19 -> 25db
16位unsigned short为2Byte,且无符号,则为0*16^3 + 0*16^2 + 1*16^1 + 9*16^0 = 25
思路是:(0x00,0x19)对应的高位为num[high]=0x00=0,低位为num[low]=0x19=25,要先把(0,25)->(0019)-,然后再计算结果。
//0x00,0x19 -> 入参为:0,25
private String toHexStr(int highByte, int lowByte){
StringBuilder sb = new StringBuilder();
if (highByte > 0) {
String high = Integer.toHexString(highByte);
if (high.length() < 2) {
sb.append('0').append(high);
} else {
sb.append(high);
}
} else {
sb.append("00");
}
if (lowByte > 0) {
String low = Integer.toHexString(lowByte);
if (low.length() < 2) {
sb.append('0').append(low);
} else {
sb.append(low);
}
} else {
sb.append("00");
}
return sb.toString();
}
//1