% These functions are responsible for creating the CCITT CRC Table and
% performing the checksum test.
%
% Implemented in Matlab by M. DeLand 6/24/2003
% Code taken from crct5.c and data.c
% Revised by Juyong Do 1/14/2009

function crc = crcTest(data)

global CRC_TABLE

crc     = uint16(0);
len     = length(data);

for i = 1:len
    a = bitshift(crc, 8, 16);
    b = bitshift(crc, -8, 16);
  
    crc = bitxor(a, CRC_TABLE(bitxor(b, data(i)) + 1));
end;

return;
        
