java 处理嵌入式数据

来源:互联网 发布:菲律宾可以用淘宝吗 编辑:程序博客网 时间:2024/06/08 17:46

 

java 处理嵌入式数据,java 无符号数char 是16位无符号, short是16位有符号, byte是8位有符号。嵌入式中比较典型的 unchar-8 转为 byte的话,如果值大于127 进行计算是有问题的。

转化可以用 int  real = value & 0xff;  或者  short real = value & 0xff


1、一些十六进制的转化:TI sensorTag  里的转化工具类写的不错



2、 使用apache 提供的 commons-codec 包

apache提供的数据处理包 对hex的处理也不错

http://commons.apache.org/proper/commons-codec/

http://commons.apache.org/proper/commons-codec/archives/1.10/apidocs/index.html


典型的如:byte[] string  char[] 之间的转换

new String(Hex.encodeHex(characteristic.getValue()))


0 0
原创粉丝点击