CRC校验实验报告_第1页
CRC校验实验报告_第2页
CRC校验实验报告_第3页
CRC校验实验报告_第4页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.实验三CRC 校验一、 CRC 校验码的基本原理编码过程:CRC 校验码的编码方法是用待发送的二进制数据 t(x) 除以生成多项式 g(x),将最后的余数作为 CRC 校验码。其实现步骤如下:1 设待发送的数据块是m 位的二进制多项式t(x),生成多项式为 r 阶的 g(x)。在数据块的末尾添加 r 个 0,数据块的长度增加到 m+r 位。2用生成多项式 g(x)去除 ,求得余数为阶数为 r-1 的二进制多项式 y(x) 。此二进制多项式 y(x)就是 t(x) 经过生成多项式g(x)编码的 CRC 校验码。3将 y(x) 的尾部加上校验码,得到二进制多项式。 就是包含了 CRC 校验码的待

2、发送字符串。解码过程:从 CRC 的编码规则可以看出, CRC 编码实际上是将代发送的m 位二进制多项式 t(x)转换成了可以被 g(x)除尽的 m+r 位二进制多项式所以解码时可以用接收到的数据去除 g( x),如果余数位零,则表示传输过程没有错误;如果余数不为零,则在传输过程中肯定存在错误。许多 CRC 的硬件解码电路就是按这种方式进行检错的。同时 ,可以看做是由t(x)和 CRC 校验码的组合,所以解码时将接收到的二进制数据去掉尾部的r 位数据,得到的就是原始数据。'.解码过程示例:'.运行结果:附录(实现代码):using System;using System.Col

3、lections.Generic;using System.Text;namespace CRCpublic abstract classChange/ <summary>/ 字节数组转进制/ </summary>/ <param name="bytes"> 字节数组 </param>/ <param name="b1"> 字节数组长度 </param>'.public static string ByteToHex(byte bytes, int b1)string ret

4、urnStr = ""if (bytes != null)for (int i = 0; i < b1; i+)returnStr += bytesi.ToString("x2").ToUpper(); return returnStr;/ <summary>/ 16 进制转字节数组/ </summary>/ <param name="hexStr">16 进制数 </param> public static byte HexToByte(string hexStr)hexStr

5、= hexStr.Replace(" ", ""); if (hexStr.Length % 2) != 0)hexStr += " "/ 空格byte bytes = new bytehexStr.Length / 2; for (int i = 0; i < bytes.Length; i+)bytesi = Convert.ToByte(hexStr.Substring(i * 2, 2), 16); return bytes;/ <summary>/ 字符串转进制/ </summary>/ <

6、;param name="str"> 字符串 </param>/ <returns></returns>public static string StrToHex(string str)if (str = "") return ""byte bTemp = System.Text.Encoding.Default.GetBytes(str); return ByteToHex(bTemp, bTemp.Length);/ <summary>'./ 16 进制转字符串/ &l

7、t;/summary>/ <param name="str">16 进制 </param>/ <returns></returns>public static string HexToStr(string str)byte bytes = new bytestr.Length;bytes = HexToByte(str);return Encoding.Default.GetString(bytes);namespace CRC/哈夫曼树150/ 结点类 Node 的定义如下:public class Nodepriva

8、te int weight; / 结点权值private int lChild; / 左孩子结点private int rChild; / 右孩子结点private int parent; / 父结点/结点权值属性public int Weightgetreturn weight;setweight = value;/左孩子结点属性public int LChild'.getreturn lChild;setlChild = value;/右孩子结点属性public int RChildgetreturn rChild;setrChild = value;/父结点属性public in

9、t Parentgetreturn parent;setparent = value;/构造器public Node()weight = 0;lChild = -1;rChild = -1;parent = -1;/构造器public Node(int w, int lc, int rc, int p)weight = w;lChild = lc;rChild = rc;parent = p;public class HuffmanTree'.private List<Node> data = new List<Node>(); / 结点数组 private i

10、nt leafNum; / 叶子结点数目/索引器public Node thisint indexgetreturn dataindex;setdataindex = value;/叶子结点数目属性public int LeafNumpublic int LeafNumgetreturn leafNum; setleafNum = value;/构造器public HuffmanTree() public HuffmanTree(List<NumKindchar> m_NumKind)leafNum = m_NumKind.Count;for (int j = 0; j <

11、2 * m_NumKind.Count - 1; j+)/n中字符共需要 2n-1 个节点Node databuff = new Node();if (j < this.leafNum)databuff.Weight = m_NumKindj.num;data.Add(databuff);/ 每创建一个节点将节点加入节点数组data 当中 '.public List<Node> Create()int max1, max2, tmp1, tmp2;/ 处理 n 个叶子结点,建立哈夫曼树for (int i = 0; i < this.leafNum - 1; +

12、i) max1 = max2 = Int32.MaxValue;tmp1 = tmp2 = 0;/在全部结点中找权值最小的两个结点for (int j = 0; j < this.leafNum + i; +j)if (dataj.Weight < max1) && (dataj.Parent = -1) max2 = max1;tmp2 = tmp1; tmp1 = j;max1 = dataj.Weight;else if (dataj.Weight < max2) && (dataj.Parent = -1)max2 = dataj.Weight;tmp2 = j;datatmp1.Parent = this.leafNum + i;datatmp2.Parent = this.leafNum + i;datathis.leafNum+i.Weight=datatmp1.Weight+datatmp2.Weight;datathis.leafNum + i.LChild = tmp1;datathis.leafNum + i.RChild = tmp2;return data;public class NumKindcharpublic char letter

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论