最近一个项目用到向终端发送数据的方法,终端是16位(4字节)的。所以需要把Int型转换为32位的,在终端按照4个字节读出,写了下面的转换方法:
1
public static class MyMath
2
}
2
测试:
int iPut = 44;
byte[] b = MyMath.intToBytes(iPut, 4);
int i = MyMath.bytesToInt(b, 0, 4);
最近一个项目用到向终端发送数据的方法,终端是16位(4字节)的。所以需要把Int型转换为32位的,在终端按照4个字节读出,写了下面的转换方法:
测试:
int iPut = 44;
byte[] b = MyMath.intToBytes(iPut, 4);
int i = MyMath.bytesToInt(b, 0, 4);
相关文章: