CRC校验实验报告Word文档格式.docx
《CRC校验实验报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《CRC校验实验报告Word文档格式.docx(9页珍藏版)》请在冰豆网上搜索。
![CRC校验实验报告Word文档格式.docx](https://file1.bdocx.com/fileroot1/2023-1/21/9ad6a7cf-48b8-442e-8eb5-b39deabf6307/9ad6a7cf-48b8-442e-8eb5-b39deabf63071.gif)
所以解码时可以用接收到的数据去除g(x),如果余数位零,则
表示传输过程没有错误;
如果余数不为零,则在传输过程中肯定
存在错误。
许多CRC的硬件解码电路就是按这种方式进行检错的。
同时,可以看做是由t(x)和CRC校验码的组合,所以解码时将接
收到的二进制数据去掉尾部的r位数据,得到的就是原始数据。
解码过程示例:
运行结果:
附录(实现代码):
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceCRC
{
publicabstractclassChange
{
///<
summary>
///字节数组转进制
/summary>
paramname="
bytes"
>
字节数组<
/param>
b1"
字节数组长度<
publicstaticstringByteToHex(byte[]bytes,intb1)
stringreturnStr="
"
;
if(bytes!
=null)
for(inti=0;
i<
b1;
i++)
returnStr+=bytes[i].ToString("
x2"
).ToUpper();
}}
returnreturnStr;
}
///16进制转字节数组
hexStr"
16进制数<
publicstaticbyte[]HexToByte(stringhexStr)
hexStr=hexStr.Replace("
"
"
);
if((hexStr.Length%2)!
=0)
hexStr+="
//空格
byte[]bytes=newbyte[hexStr.Length/2];
bytes.Length;
bytes[i]=Convert.ToByte(hexStr.Substring(i*2,2),16);
}
returnbytes;
///字符串转进制
str"
字符串<
returns>
<
/returns>
publicstaticstringStrToHex(stringstr)
if(str=="
)return"
byte[]bTemp=System.Text.Encoding.Default.GetBytes(str);
returnByteToHex(bTemp,bTemp.Length);
///16进制转字符串
16进制<
publicstaticstringHexToStr(stringstr)
byte[]bytes=newbyte[str.Length];
bytes=HexToByte(str);
returnEncoding.Default.GetString(bytes);
}
//哈夫曼树150
//结点类Node的定义如下:
publicclassNode
privateintweight;
//结点权值
privateintlChild;
//左孩子结点
privateintrChild;
//右孩子结点
privateintparent;
//父结点
//结点权值属性
publicintWeight
get
returnweight;
set
weight=value;
//左孩子结点属性
publicintLChild
returnlChild;
lChild=value;
//右孩子结点属性
publicintRChild
{returnrChild;
set{rChild=value;
//父结点属性
publicintParent
{get
{returnparent;
set{
parent=value;
//构造器
publicNode()
weight=0;
lChild=-1;
rChild=-1;
parent=-1;
publicNode(intw,intlc,intrc,intp)
weight=w;
lChild=lc;
rChild=rc;
parent=p;
publicclassHuffmanTree
privateList<
Node>
data=newList<
();
//结点数组
privateintleafNum;
//叶子结点数目
//索引器
publicNodethis[intindex]
returndata[index];
data[index]=value;
//叶子结点数目属性publicintLeafNum
publicintLeafNum
{returnleafNum;
{leafNum=value;
publicHuffmanTree()
{}
publicHuffmanTree(List<
NumKindchar>
m_NumKind)
leafNum=m_NumKind.Count;
for(intj=0;
j<
2*m_NumKind.Count-1;
j++)//n中字符共需要2n-1个节点
Nodedatabuff=newNode();
if(j<
this.leafNum)
databuff.Weight=m_NumKind[j].num;
data.Add(databuff);
//每创建一个节点将节点加入节点数组data当中}
publicList<
Create()
intmax1,max2,tmp1,tmp2;
//处理n个叶子结点,建立哈夫曼树
this.leafNum-1;
++i)
{max1=max2=Int32.MaxValue;
tmp1=tmp2=0;
//在全部结点中找权值最小的两个结点
this.leafNum+i;
++j)
{if((data[j].Weight<
max1)&
&
(data[j].Parent==-1))
{max2=max1;
tmp2=tmp1;
tmp1=j;
max1=data[j].Weight;
elseif((data[j].Weight<
max2)&
{max2=data[j].Weight;
tmp2=j;
}}
data[tmp1].Parent=this.leafNum+i;
data[tmp2].Parent=this.leafNum+i;
data[this.leafNum+i].Weight=data[tmp1].Weight+data[tmp2].Weight;
data[this.leafNum+i].LChild=tmp1;
data[this.leafNum+i].RChild=tmp2;
returndata;
}}
publicclassNumKindchar
{publiccharletter{get;
set;
}//字符
publicintnum{get;
}//字符出现的次数
bool>
huffmancode{get;
}//字符对应的huffman编码
publicclasscodeChar
publiccharnumChar{get;
publicstringcodeCharater{get;