| | |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * short转为字节数组 |
| | | * @param data |
| | | * @return 包含2个字节的字节数组 |
| | | */ |
| | | public static byte[] shortGetBytes(short data) { |
| | | byte[] bytes = new byte[2]; |
| | | bytes[0] = (byte) (data & 0xff); |
| | | bytes[1] = (byte) ((data & 0xff00) >> 8); |
| | | return bytes; |
| | | } |
| | | |
| | | public static byte[] shortGetByte(short data){ |
| | | byte[] bytes = new byte[1]; |
| | | bytes[0] = (byte)(data & 0xff); |
| | | return bytes; |
| | | } |
| | | |
| | | public static void main(String[] args){ |
| | | System.out.println(byte2HexStr(shortGetBytes((short) 65535))); |
| | | short b = (short) 32768; |
| | | b++; |
| | | System.out.println(byte2HexStr(shortGetBytes((short) b))); |
| | | } |
| | | |
| | | } |