经测结果一致,直接源码给需要的同学
private static void Crc1(byte value, ref ushort crc) { byte bt = value; for (int i = 0; i < 8; i++) { bool b1 = (crc & 0x8000U) != 0; bool b2 = (bt & 0x80U) != 0; if (b1 != b2) crc = (ushort)((crc << 1) ^ 0x1021); else crc <<= 1; bt <<= 1; } }
private static void Crc2(byte value, ref ushort crc) { byte bt = 0; for (int i = 0; i < 8; i++) { bt = (byte)(((value << i) & 0x80) ^ ((crc & 0x8000) >> 8)); crc <<= 1; if (bt != 0) crc ^= 0x1021; } }
private static void Crc3(byte value, ref ushort crc) { for (int i = 0; i < 8; i++) { bool bit = ((value >> (7 - i) & 1) == 1); bool c15 = ((crc >> 15 & 1) == 1); crc <<= 1; if (c15 ^ bit) crc ^= 0x1021; } }
|