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
x=mycrc(data,divisor,type)
x : 输出
data : 输入
divisor: 8 或者 16
type : 1 或者 2
1 新建m文件,把函数function [ output, indicate] = crc_check( input, crc_no )贴进去保存;2 新建m文件,把函数function [ output ] = crc_add( input, crc_no )贴进去保存;
3 在command window里输入
clear all
input=[1 1 0 0]
CRC_Number=[3 8 12 16]
for crc_index = 1:size(CRC_Number,2)
crc_no = CRC_Number(crc_index)
output = crc_add(input, crc_no)
[output_after_check, indicate] =crc_check(output,crc_no)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rc_check和crc_add相当于函数,你要调用这2个函数,所以应先将函数保存,再进行调用。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)