function out=crc_24(msg) g0=ones(1,24); N=length(msg); g2(1)=xor(msg(1),g0(1)); g0=circshift(g0,[0,-1]);%g0=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 ]; g0(1)=xor(g2(1),g0(2)); g0(6)=xor(g2(1),g0(7)); g0(7)=xor(g2(1),g0(8)); g0(10)=xor(g2(1),g0(11)); g0(13)=xor(g2(1),g0(14)); g0(14)=xor(g2(1),g0(15)); g0(17)=xor(g2(1),g0(18)); g0(18)=xor(g2(1),g0(19)); g0(19)=xor(g2(1),g0(20)); g0(20)=xor(g2(1),g0(21)); g0(21)=xor(g2(1),g0(22)); g0(23)=xor(g2(1),g0(24)); g0(24)=g2(1); if N>1 for i=2:N k=g0; g2(i)=xor(msg(i),g0(1)); g0=circshift(g0,[0,-1]); g0(24)=g2(i); g0(23)=xor(g2(i),k(24)); g0(21)=xor(g2(i),k(22)); g0(20)=xor(g2(i),k(21)); g0(19)=xor(g2(i),k(20)); g0(18)=xor(g2(i),k(19)); g0(17)=xor(g2(i),k(18)); g0(14)=xor(g2(i),k(15)); g0(13)=xor(g2(i),k(14)); g0(10)=xor(g2(i),k(11)); g0(7)=xor(g2(i),k(8)); g0(6)=xor(g2(i),k(7)); g0(1)=xor(g2(i),k(2)); end end % out=g0; out=g0;