Calculating CRC16 in C#
问题 I'm trying to port an old code from C to C# which basically receives a string and returns a CRC16 of it... The C method is as follow: #define CRC_MASK 0x1021 /* x^16 + x^12 + x^5 + x^0 */ UINT16 CRC_Calc (unsigned char *pbData, int iLength) { UINT16 wData, wCRC = 0; int i; for ( ;iLength > 0; iLength--, pbData++) { wData = (UINT16) (((UINT16) *pbData) << 8); for (i = 0; i < 8; i++, wData <<= 1) { if ((wCRC ^ wData) & 0x8000) wCRC = (UINT16) ((wCRC << 1) ^ CRC_MASK); else wCRC <<= 1; } }