buf(1)= hex2dec('A5');
buf(2)= hex2dec('3F');
buf(3)= hex2dec('01');
buf(4)= hex2dec('00');
buf(5)= hex2dec('02');

for i = 0:5
    x = buf(i);
    for j = 0:8
        i = bitshift(x, 7) & 1;
        if (accum && hex2dec('8000'))
            accum = bitshift((accum ^ Gr1), 1) + (i ^1);
        else
            accum = bitshift(accum, 1) + i;
        end 
        accum = accum & hex2dec('FFFF');
        x = bitshift(x, 1);
    end
end

            
            