To calculate CRC I found a piece of code but I am not understanding the concept. Here is the code:
count =128 and ptr=some value;
calcrc(unsigned char *ptr, int count)
{
    unsigned short  crc;
    unsigned char i;
    crc = 0;
    while (--count >= 0)
    {
        crc = crc ^ (unsigned short)*ptr++ << 8;
        i = 8;
        do
        {
            if (crc & 0x8000)
                crc = crc << 1 ^ 0x1021;
            else
                crc = crc << 1;
        } while(--i);
    }
    return (crc);
}
Please any body explain and tell me the logic.