




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、實(shí)驗(yàn)三 CRC校驗(yàn)一、CRC校驗(yàn)碼的基本原理編碼過程:CRC校驗(yàn)碼的編碼方法是用待發(fā)送的二進(jìn)制數(shù)據(jù)t(x)除以生成多項(xiàng)式g(x),將最后的余數(shù)作為CRC校驗(yàn)碼。其實(shí)現(xiàn)步驟如下: 1 設(shè)待發(fā)送的數(shù)據(jù)塊是m位的二進(jìn)制多項(xiàng)式t(x),生成多項(xiàng)式 為r階的g(x)。在數(shù)據(jù)塊的末尾添加r個(gè)0,數(shù)據(jù)塊的長(zhǎng)度增 加到m+r位。 2 用生成多項(xiàng)式g(x)去除 ,求得余數(shù)為階數(shù)為r-1的二進(jìn)制 多項(xiàng)式y(tǒng)(x)。此二進(jìn)制多項(xiàng)式y(tǒng)(x)就是t(x)經(jīng)過生成多項(xiàng)式 g(x)編碼的CRC校驗(yàn)碼。 3 將y(x)的尾部加上校驗(yàn)碼,得到二進(jìn)制多項(xiàng)式 。 就是包含 了CRC校驗(yàn)碼的待發(fā)送字符串。解碼過程: 從CRC的編碼規(guī)則
2、可以看出,CRC編碼實(shí)際上是將代發(fā)送的m位二進(jìn)制多項(xiàng)式t(x)轉(zhuǎn)換成了可以被g(x)除盡的m+r位二進(jìn)制多項(xiàng)式所以解碼時(shí)可以用接收到的數(shù)據(jù)去除g(x),如果余數(shù)位零,則表示傳輸過程沒有錯(cuò)誤;如果余數(shù)不為零,則在傳輸過程中肯定存在錯(cuò)誤。許多CRC的硬件解碼電路就是按這種方式進(jìn)行檢錯(cuò)的。同時(shí),可以看做是由t(x)和CRC校驗(yàn)碼的組合,所以解碼時(shí)將接收到的二進(jìn)制數(shù)據(jù)去掉尾部的r位數(shù)據(jù),得到的就是原始數(shù)據(jù)。解碼過程示例:運(yùn)行結(jié)果:附錄(實(shí)現(xiàn)代碼):using System;using System.Collections.Generic;using System.Text;namespace CRC
3、public abstract class Change / <summary> / 字節(jié)數(shù)組轉(zhuǎn)進(jìn)制 / </summary> / <param name="bytes">字節(jié)數(shù)組</param> / <param name="b1">字節(jié)數(shù)組長(zhǎng)度</param> public static string ByteToHex(byte bytes, int b1) string returnStr = "" if (bytes != null) for (int
4、i = 0; i < b1; i+) returnStr += bytesi.ToString("x2").ToUpper(); return returnStr; / <summary> / 16進(jìn)制轉(zhuǎn)字節(jié)數(shù)組 / </summary> / <param name="hexStr">16進(jìn)制數(shù)</param> public static byte HexToByte(string hexStr) hexStr = hexStr.Replace(" ", "")
5、; 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> / 字符串轉(zhuǎn)進(jìn)制 / </summary> / <param name="str">字符串</
6、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進(jìn)制轉(zhuǎn)字符串 / </summary> / <param name="str
7、">16進(jìn)制</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 / 結(jié)點(diǎn)類Node的定義如下: public class Node private int weight; /結(jié)點(diǎn)權(quán)值 private int
8、lChild; /左孩子結(jié)點(diǎn) private int rChild; /右孩子結(jié)點(diǎn) private int parent; /父結(jié)點(diǎn) /結(jié)點(diǎn)權(quán)值屬性 public int Weight get return weight; set weight = value; /左孩子結(jié)點(diǎn)屬性 public int LChild get return lChild; set lChild = value; /右孩子結(jié)點(diǎn)屬性 public int RChild get return rChild; set rChild = value; /父結(jié)點(diǎn)屬性 public int Parent get return
9、parent; set parent = value; /構(gòu)造器 public Node() weight = 0;lChild = -1; rChild = -1; parent = -1; /構(gòu)造器 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>(); /結(jié)點(diǎn)數(shù)組 private int leafNum
10、; /葉子結(jié)點(diǎn)數(shù)目 /索引器 public Node thisint index get return dataindex; set dataindex = value; /葉子結(jié)點(diǎn)數(shù)目屬性public int LeafNum public int LeafNum get return leafNum; set leafNum = value; /構(gòu)造器 public HuffmanTree() public HuffmanTree(List<NumKindchar> m_NumKind) leafNum = m_NumKind.Count; for (int j = 0; j &
11、lt; 2 * m_NumKind.Count - 1; j+)/n中字符共需要2n-1個(gè)節(jié)點(diǎn) Node databuff = new Node(); if (j < this.leafNum) databuff.Weight = m_NumKindj.num; data.Add(databuff);/每創(chuàng)建一個(gè)節(jié)點(diǎn)將節(jié)點(diǎn)加入節(jié)點(diǎn)數(shù)組data當(dāng)中 public List<Node> Create() int max1, max2, tmp1, tmp2; /處理n個(gè)葉子結(jié)點(diǎn),建立哈夫曼樹 for (int i = 0; i < this.leafNum - 1; +i)
12、 max1 = max2 = Int32.MaxValue; tmp1 = tmp2 = 0; /在全部結(jié)點(diǎn)中找權(quán)值最小的兩個(gè)結(jié)點(diǎn) 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 NumKindchar public char let
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 精心編排2024年園藝師考試輔助材料試題及答案
- 解決農(nóng)藝師考試疑難試題及答案匯編
- 山東省郯城第三中學(xué)初中信息技術(shù) 第1課 創(chuàng)建站點(diǎn)教學(xué)設(shè)計(jì)
- 文科類學(xué)生試題及答案解析
- 強(qiáng)化記憶:2024年珠寶鑒定師考試試題及答案
- 自然資源管理試題及答案
- 常見園藝病蟲害識(shí)別試題及答案
- 2024年福建事業(yè)單位考試解析應(yīng)試試題及答案
- 2024年輔導(dǎo)員崗位考試領(lǐng)導(dǎo)力與團(tuán)隊(duì)管理試題及答案
- 江蘇中考化學(xué)試題及答案
- 《食品感官分析技術(shù)》最全完整版課件全套教學(xué)教程
- 三年級(jí)下冊(cè)數(shù)學(xué)課件-4.1 整體與部分 ▏滬教版 (共21張ppt)
- 【課件】抒情與寫意-文人畫 課件高中美術(shù)人美版(2019)美術(shù)鑒賞
- 14.1獸藥陳列環(huán)境溫濕度記錄表
- 戰(zhàn)略管理學(xué)英文課件:14 Leadership and Strategic Change
- 遼寧省地方標(biāo)準(zhǔn)編制說明
- (完整word)燃油系統(tǒng)完整性(FMVSS 301)
- 質(zhì)性研究方法3-質(zhì)性研究的編碼課件
- PRS-7741-102技術(shù)使用說明書
- 心理治療師考試精讀與習(xí)題
- 幼兒園中班數(shù)學(xué):《區(qū)別基數(shù)與序數(shù)》 課件
評(píng)論
0/150
提交評(píng)論