crc16.m

来自「《Home Networking Basis》(《家庭网络基础》)的配套MATL」· M 代码 · 共 20 行

M
20
字号
%Variable initialization
gx=[1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1];
x=ceil(rand(1,1000)*2-1);
x=[x zeros(1,16)];
%Mathematically, the CRC value corresponding to a given frame 
%is defined by the following procedure.
%  The first 16 bits of the input bit sequence are complemented.
rx=bitcmp(x(1:16),1);
%  The bit sequence is divided by G(x), producing a remainder 
%  R(x) of degree <= 15.
for i=1:1000
    nm=[rx x(i+16)];
    if nm(1)==1
        rx=xor(nm(2:17),gx(2:17));
    else
        rx=nm(2:17);
    end
end
rx=bitcmp(rx,1);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?