from
Simple CRC calculator and veifier
by Ai Murtaza Shaikh
Simple program that calculates crc for a 7 bit binary data using a 4bit crc polynomial.
|
| x=mycrc(data,divisor,type)
|
function x=mycrc(data,divisor,type)
if ((type==1)||(type==2))
n=length(divisor)
appender=[0 0 0 0]
dividend=[data]
if ((type==1))
dividend=[data,appender]
end
dividendA=dividend(1:5)
dividendB=dividend(6:length(dividend))
result=dividendA
while((n-1)~=length(result))
result=bitxor(result,divisor)
while(result(1)==0 && ((n-1)~=length(result)))
result=result(2:length(result))
if ((length(result)<length(divisor)) && (length(dividendB)~=0))
result=[result,dividendB(1)]
dividendB=dividendB(2:length(dividendB))
end
end
end
x=result
if (type==2 & result==zeros(size(result)))
x=[1];
disp('check successful,data uncorrupted')
elseif (type==2)
x=[0]
disp('check failed data is corrupted')
end
else
disp('invalid type entered in 3rd parameter it should either be 1 or 2')
end
|
|
Contact us at files@mathworks.com