- uint_8
无符号 8 位整型,单字节传输
String s = String.format("%02X",data[0]));
int c = Integer.parseInt(s, 16);
- uint_16
无符号 16 位整型,高字节在前,低字节在后。如原值为 18624,传输先后
顺序为:0x48,0xC0;
String s = String.format("%02X",data[0]) + String.format("%02X",data[1]);
int c = Integer.parseInt(s, 16);
- uint_32
无符号 32 位整型,高字节在前,低字节在后。如原值为 741589674,传输
先后顺序为 0x2C,0x33,0xC2,0xAA;
String s = String.format("%02X",data[0]) + String.format("%02X",data[1]) + String.format("%02X",data[2]) + String.format("%02X",data[3]);
long c = Long.parseLong(s, 16);
- BCD 码
如时间点 12:00,传输先后顺序为 0x12,0x00;
StringBuffer stringBuffer = new StringBuffer();
for (int i =0 ; i < bytes.length; i++){
stringBuffer.append(String.format("%02x",bytes[i]));
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
Long parse = simpleDateFormat.parse(stringBuffer.toString()).getTime() / 1000;
- ASCII
字符型,按字符流传输。如字符串"KeHua",传输先后顺序为"K","e","H
","u","a";
byte[] codeData = ByteUtils.copy(bytes, from, len);
return new String(codeData);