#include <stdio.h>
int main(void) {
// your code goes here
unsigned short int crc = 0; // Result
unsigned char command[4]={0x76,0x05,0x04,0xA1};// command, ID, arg1, arg2
char x, y;
crc=0xFFFF; //init value
for (x=0; x<4; x++)
{
crc = ( ( command[x] <<8 ) ^ crc);
for ( y=0; y<8; y++ )
{
if ( crc & 0x8000 )
crc = (crc << 1) ^ 0x8005;
else
crc = crc << 1;
}
}
printf ("CRC: %X\n",crc
); // must print CRC: return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCgkKCXVuc2lnbmVkIHNob3J0IGludCBjcmMgPSAwOyAvLyBSZXN1bHQKdW5zaWduZWQgY2hhciBjb21tYW5kWzRdPXsweDc2LDB4MDUsMHgwNCwweEExfTsvLyBjb21tYW5kLCBJRCwgYXJnMSwgYXJnMgoKY2hhciB4LCB5OwogY3JjPTB4RkZGRjsgLy9pbml0IHZhbHVlCgpmb3IgKHg9MDsgeDw0OyB4KyspCnsKY3JjID0gKCAoIGNvbW1hbmRbeF0gPDw4ICkgXiBjcmMpOwpmb3IgKCB5PTA7IHk8ODsgeSsrICkKCnsKIGlmICggY3JjICYgMHg4MDAwICkKY3JjID0gKGNyYyA8PCAxKSBeIDB4ODAwNTsKCmVsc2UKY3JjID0gY3JjIDw8IDE7Cgp9Cn0KcHJpbnRmICgiQ1JDOiAlWFxuIixjcmMpOyAvLyBtdXN0IHByaW50IENSQzoKCXJldHVybiAwOwp9Cg==