#include<stdio.h>

static int maxargs = 100;

unsigned int crc16(char* buffer,int length)
{
  unsigned int crc = 0xFFFF;
  unsigned int c;
  static unsigned int magic = 0xA001;
  int x;
  int y;
  int z;
  int count;
  for (x = 0; x < length; ++x)
    {
      count = 0;
      c = buffer[x] & 0x00FF;
      crc = crc ^ c;
      for (y = 0; y < 8;++y)
	{
	  z = crc % 2;
	  crc = crc>>1;
	  if (z == 1)
	    {
	      crc = crc^magic;
	    }
	}
    }
  return crc;
}


main( int argc, char *argv[] )
{
  unsigned int res;
  unsigned int hi;
  unsigned int lo;
  unsigned char input[maxargs];
  if (argc > maxargs +1)
    {
      printf("Too many arguments!\n");
      return 1;
    }
  int x;
  unsigned int y = 0;
  for (x = 1; x < argc;++x)
    {
      sscanf(argv[x],"%02x",&y);
      input[x-1] = y;
    }
  res = crc16(input,argc-1);
  hi = res / 256;
  lo = res % 256;
  printf("%02x %02x\n",lo,hi);
  return 0;
}

