| | |
| | | */ |
| | | public static byte[] shortGetBytes(short data) { |
| | | byte[] bytes = new byte[2]; |
| | | bytes[0] = (byte) (data & 0xff); |
| | | bytes[1] = (byte) ((data & 0xff00) >> 8); |
| | | bytes[1] = (byte) (data & 0xff); |
| | | bytes[0] = (byte) ((data & 0xff00) >> 8); |
| | | return bytes; |
| | | } |
| | | |
| | |
| | | short b = (short) 32768; |
| | | b++; |
| | | System.out.println(byte2HexStr(shortGetBytes((short) b))); |
| | | |
| | | |
| | | String model = "123"; |
| | | byte[] messageBody = new byte[30]; |
| | | byte[] modelBytes = new byte[20]; |
| | | modelBytes = model.getBytes(); |
| | | System.arraycopy(shortGetBytes((short)323),0,messageBody,0,2); |
| | | System.arraycopy(modelBytes,0,messageBody,2,modelBytes.length); |
| | | System.arraycopy(shortGetBytes((short)3),0,messageBody,22,2); |
| | | System.out.println(byte2HexStr(messageBody)); |
| | | |
| | | } |
| | | |
| | | public static byte[] subArray(byte[] srcBytes, int begin, int length) { |