/*
 * CRC.c
 *
 * Created: 17.3.2015 10:45:53
 *  Author: Matej
 */ 

#include "CRC.h"

WORD getCRC16(BYTE *pbyData, DWORD nData, WORD wPoly, WORD wStart)
{
	DWORD ix;
	WORD wCRC, jx;
	BYTE byAux;
	wCRC = wStart;
	for( ix=0; ix<nData; ix++ )
	{
		byAux=pbyData[ix];
		for( jx=0; jx<8; jx++ )
		{
			if( wCRC & 0x8000 )
			{
				wCRC = (wCRC<<1)| (byAux & 1);
				wCRC ^= wPoly;
			}
			else
			wCRC = (wCRC<<1)| (byAux & 1);
			byAux >>= 1;
		}
	}
	return wCRC;
}

