📄 hcs.m
字号:
%Variable initialization
gx=[1 1 1 0 1 0 1 0 1];
hx=[1 1 1 1 0 1 1 1];
FT=[0 0 0 0 0 0 0 0];
RSVD=[0];
PRI=[0 1 0];
SI=[0 1 0 0];
PE=[0 0 0 0 1 0 1 0];
HCS=[0 0 0 0 0 0 0 0];
FC=[FT RSVD PRI SI PE HCS];
DA=ceil(rand(1,48)*2-1);
SA=ceil(rand(1,48)*2-1);
FC2SA=[FC DA SA];
%Mathematically, the CRC value corresponding to a given frame
%is defined by the following procedure.
% The first 8 bits of the input bit sequence are complemented.
FC2SA(1:8)=bitcmp(FC2SA(1:8),1);
% The 128 bits of the sequence is multiplied by x^8 and divided
% by G(x), producing a remainder R(x) of degree <= 7.
FC2SA=[FC2SA zeros(1,8)];
rx=FC2SA(1:8);
for i=1:128
nm=[rx FC2SA(i+8)];
if nm(1)==1
rx=xor(nm(2:9),gx(2:9));
else
rx=nm(2:9);
end
end
% R(x) is multiplied by H(x) to produce N(x)
nx(1:8)=rx;
for i=1:7
if hx(i+1)==1
nx(i+1:i+7)=xor(rx(1:7),nx(i+1:i+7));
nx(i+8)=rx(8);
else
nx(i+8)=0;
end
end
% N(x) is divided by G(x), producing a remainder R'(x) of degree <= 7.
rrx=nx(1:8);
for i=1:7
nm=[rrx nx(i+8)];
if nm(1)==1
rrx=xor(nm(2:9),gx(2:9));
else
rrx=nm(2:9);
end
end
% The bit sequence is complemented and the result is the CRC'.
rrx=bitcmp(rrx,1);
%The 8 bits of the CRC' are placed in the HCS field so that x^7 is
%the least-significant bit of the octet and x^0 term is the
%most-significant bit of the octet. The bits of the CRC' are thus
%transmitted in the order x^7, x^6, .. x^1, x^0.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -