Below is some real working C source code. Borrowed from here!
It is tested and working. It calculates CRC CCITT16 with starting value 0xFFFF. It might be not as fast as table based CRC calculations, but occupies less RAM and code space which sometimes is essential for embedded systems.
#define POLY 0x1021 unsigned char i; unsigned int crc = 0xFFFF; while (wLength--) { wCrc ^= *(unsigned char *)pData++ << 8; for (i=0; i < 8; i++) wCrc = wCrc & 0x8000 ? (wCrc << 1) ^ POLY : wCrc << 1; } return wCrc & 0xffff;