- public static byte[] intToByte(int cmd) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream ds = new DataOutputStream(baos);
- try {
- ds.writeInt(cmd);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return baos.toByteArray();
- }
- public static void main(String[] args) {
- int packageMark = 0x5544a1a1;
- byte[] bye = new byte[4];
- bye = intToByte(packageMark);
- for(int i=0; i<bye.length; i++) {
- System.out.print(bye[i]+" ");
- }
- 结果:85 68 -95 -95 为什么有负数,怎样才能是正数呢??
复制代码
|
|