/** * int转换为小端byte[](高位放在高地址中) * * @param iValue * @return */ public static byte[] Int2Bytes_LE(int iValue) { byte[] rst = new byte[4]; // 先写int的最后一个字节 rst[0] = (byte) (iValue & 0xFF); // int 倒数第二个字节 rst[1] = (byte) ((iValue & 0xFF00) >> 8); // int 倒数第三个字节 rst[2] = (byte) ((iValue & 0xFF0000) >> 16); // int 第一个字节 rst[3] = (byte) ((iValue & 0xFF000000) >> 24); return rst; } public static int CRC_XModem(byte[] bytes) { int crc = 0x00; // initial value int polynomial = 0x1021; for (int index = 0; index < bytes.length; index++) { byte b = bytes[index]; for (int i = 0; i < 8; i++) { boolean bit = ((b >> (7 - i) & 1) == 1); boolean c15 = ((crc >> 15 & 1) == 1); crc <<= 1; if (c15 ^ bit) crc ^= polynomial; } } crc &= 0xffff; return crc; }