1.CRCåçç®ä»
2.c#压缩解压 文件夹
CRCåçç®ä»
æè¿å好ææ¶é´ï¼æ´çäºä¸ä¸å ³äºCRCçèµæï¼è¯¦ç»å¯¹æ¯äºä¸ç¨åºçå®ç°è¿ç¨ååçï¼å½ç¶ï¼é«æé½æ¯ä¸å¨æçã
æ¬æ主è¦ä»ç»CRCçä¸äºåºç¡ç¥è¯ï¼ä¸ªäººæ¶è·æ¯åé¢å ³äºç½ä¸æ åDemoç¨åºçä¸äºè¯¦ç»è§£æãè§ä¸ä¸ç¯/p/c0dc2ece
声æï¼æ¬æå®ä¹é¨ååèç½ä¸å¤å¤èµæï¼åªæ¯ä¸ºäºæ¹ä¾¿å个ç¬è®°ï¼å¼ç¨ç½æåä¸äºæ´æ¹ï¼å¦æé·åï¼è¯·ç§ä¿¡è¯´æ并修æ¹ã
ä¸ãå ³äºCRCçä»ç»
CRCå³å¾ªç¯åä½æ ¡éªç ï¼Cyclic Redundancy Checkï¼ï¼æ°æ®éä¿¡é¢åä¸æ常ç¨çä¸ç§å·®éæ ¡éªç ï¼å ¶ä¿¡æ¯å段åæ ¡éªå段é¿åº¦å¯ä»¥ä»»ææå®ï¼ä½è¦æ±éä¿¡åæ¹å®ä¹çCRCæ åä¸è´ã
äºãå·¥ä½åç
对äºå·¥æ§é¢åï¼æ们主è¦å©ç¨CRCæ ¡éªæ¥å¤çåç§æ°æ®æµçæ°æ®æ£ç¡®æ§æ ¡éªã
CRCåç ï¼å¨Kä½ä¿¡æ¯ç ï¼ç®æ åéæ°æ®ï¼ååæ¼æ¥Rä½æ ¡éªç ï¼ä½¿æ´ä¸ªç¼ç é¿åº¦ä¸ºNä½ï¼å æ¤è¿ç§ç¼ç ä¹å«ï¼N,Kï¼ç ãéä¿ç说ï¼å°±æ¯å¨éè¦åéçä¿¡æ¯åé¢éå ä¸ä¸ªæ°ï¼å³æ ¡éªç ï¼ï¼çæä¸ä¸ªæ°çåéæ°æ®åéç»æ¥æ¶ç«¯ãè¿ä¸ªæ°æ®è¦æ±è½å¤ä½¿çæçæ°æ°æ®è¢«ä¸ä¸ªç¹å®çæ°æ´é¤ãè¿éçæ´é¤éè¦å¼å ¥æ¨¡ 2é¤æ³çæ¦å¿µï¼éä¸ç¾åº¦ç¾ç§å ³äºæ¨¡2计ç®çé¾æ¥ï¼
/item/模2è¿ç®/?fr=aladdin
é£ä¹ï¼CRCæ ¡éªçå ·ä½åæ³å°±æ¯
ï¼1ï¼éå®ä¸ä¸ªæ åé¤æ°ï¼Kä½äºè¿å¶æ°æ®ä¸²ï¼
ï¼2ï¼å¨è¦åéçæ°æ®ï¼mä½ï¼åé¢å ä¸K-1ä½0ï¼ç¶åå°è¿ä¸ªæ°æ°ï¼M+K-1ä½ï¼ä»¥æ¨¡2é¤æ³çæ¹å¼é¤ä»¥ä¸é¢è¿ä¸ªæ åé¤æ°ï¼æå¾å°çä½æ°ä¹å°±æ¯è¯¥æ°æ®çCRCæ ¡éªç ï¼æ³¨ï¼ä½æ°å¿ é¡»æ¯é¤æ°å°ä¸åªå°ä¸ä½ï¼ä¸å¤å°±è¡¥0ï¼
ï¼3ï¼å°è¿ä¸ªæ ¡éªç éå¨åmä½æ°æ®åé¢ï¼æææ°çM+K-1ä½æ°æ®ï¼åéç»æ¥æ¶ç«¯ã
ï¼4ï¼æ¥æ¶ç«¯å°æ¥æ¶å°çæ°æ®é¤ä»¥æ åé¤æ°ï¼å¦æä½æ°ä¸º0å认为æ°æ®æ£ç¡®ã
注æï¼ CRCæ ¡éªä¸æä¸¤ä¸ªå ³é®ç¹ï¼ä¸æ¯è¦é¢å ç¡®å®ä¸ä¸ªåé端åæ¥æ¶ç«¯é½ç¨æ¥ä½ä¸ºé¤æ°çäºè¿å¶æ¯ç¹ä¸²ï¼æå¤é¡¹å¼ï¼ï¼äºæ¯æåå§å¸§ä¸ä¸é¢éå®çé¤è¿è¡äºè¿å¶é¤æ³è¿ç®ï¼è®¡ç®åºFCSãåè å¯ä»¥éæºéæ©ï¼ä¹å¯æå½é ä¸éè¡çæ åéæ©ï¼ä½æé«ä½åæä½ä½å¿ é¡»å为â1â
å®ä¾ï¼å¯¹äºæ°æ®ï¼#B3ï¼ï¼ä»¥æå®é¤æ°æ±å®çCRCæ ¡éªç ï¼å ¶è¿ç¨å¦ä¸ï¼
å ³äºæ ¡éªç ç计ç®ï¼éç¹æ¥äºï¼
å纯è°CRCç模2é¤æ³å ¶å®å¹¶ä¸å°é¾ï¼ä½å®é 计ç®ä¸ç»å¸¸ä¼éå°è®¡ç®åºæ¥çç»æåå®é ä¸ä¸è´çæ åµï¼è¿ä¹æ¯è¿å 天æå¨ççä¸è¥¿ã
è¿ééè¦ç¥éå 个ç»æé¨åæè 说计ç®æ¦å¿µï¼å¤é¡¹å¼å ¬å¼ãå¤é¡¹å¼ç®è®°å¼ãæ°æ®å®½åº¦ãåå§å¼ãç»æå¼æå¼ãè¾å ¥å¼å转ãè¾åºå¼å转ãåæ°æ¨¡åã
1ãå¤é¡¹å¼å ¬å¼
对äºCRCæ åé¤æ°ï¼ä¸è¬ä½¿ç¨å¤é¡¹å¼ï¼æäºé¡¹å¼ï¼å ¬å¼è¡¨ç¤ºï¼å¦ä¸ä¾ä¸é¤æ°çäºé¡¹å¼ä¸ºG(X)=X4+X3+X+1ï¼Xçææ°å°±ä»£è¡¨äºè¯¥bitä½ä¸çæ°æ®ä¸º1,ï¼æä½ä½ä¸º0ï¼ãè¿éç¹å«æ³¨æä¸ä¸ä½æ°é®é¢ï¼é¤æ°çä½æ°ä¸ºäºé¡¹å¼æé«æ¬¡å¹+1ï¼4+1=5ï¼ï¼è¿ä¸ªå¾éè¦ã
2ãå¤é¡¹å¼ç®è®°å¼
éè¿å¯¹CRCçåºæ¬äºè§£æ们ç¥éï¼å¤é¡¹å¼çé¦å°¾å¿ å®ä¸º1ï¼èè¿ä¸ª1çä½ç½®å¨ä¸ä¸æ¥è®¡ç®ä¸å®ä¸º0ï¼æ以就æåé¢è¿ä¸ª1ç»çç¥æäºï¼åºç°äºä¸ä¸ªå«ç®è®°å¼çä¸è¥¿ï¼å¦ä¸ä¾ä¸é¤æ°çç®è®°å¼ä¸ºï¼å¾å¤çè¿CRCé«çº§è¯è¨æºç ç人ä¼ç¥éï¼å¯¹äºCRC_æ åä¸G(X)=X+X+X2+1ï¼#ï¼çpolyå¼å®é ä¸æ¯ï¼è¿é使ç¨çå°±æ¯ç®è®°å¼ãåé¢ä¼å¯¹è¿ä¸ªç¨æ³åä¸ä¸ªè¯´æã
3ãæ°æ®å®½åº¦
æ°æ®å®½åº¦æçå°±æ¯CRCæ ¡éªç çé¿åº¦ï¼äºè¿å¶ä½æ°ï¼ï¼ç¥éäºCRCçè¿ç®æ¦å¿µåå¤é¡¹å¼ï¼å°±å¯ä»¥ç解è¿ä¸ªæ¦å¿µäºï¼CRCé¿åº¦å§ç»è¦æ¯é¤æ°ä½æ°å°1ï¼ä¸ç®è®°å¼é¿åº¦æ¯ä¸è´çã
以ä¸ä¸ä¸ªæ°æ®å°±æ¯æ们ç»å¸¸è½å¤ç¨å°çåºæ¬æ°æ®
4ãåå§å¼ä¸ç»æå¼æå¼
å¨ä¸äºæ åä¸ï¼è§å®äºåå§å¼ï¼åæ°æ®å¨è¿è¡ä¸è¿°äºé¡¹å¼è¿ç®ä¹åï¼éè¦å å°è¦è®¡ç®çæ°æ®ä¸åå§å¼çæä½åèè¿è¡å¼æï¼ç¶ååä¸å¤é¡¹å¼è¿è¡è®¡ç®ã
èå¨ç»æå¼æå¼ä¸ä¸ºé¶çæ åµä¸ï¼åéè¦å°è®¡ç®å¾å°çCRCç»æå¼åä¸ç»æå¼æå¼è¿è¡ä¸æ¬¡å¼æ计ç®ï¼å¾å°çæç»å¼ææ¯æ们éè¦çCRCæ ¡éªç ã
è¿éå¯ä»¥çåºï¼åå§å¼ä¸ç»æå¼çä½æ°è¦æ±ä¸æ°æ®å®½åº¦ä¸è´ã
5ãè¾å ¥å¼å转ä¸è¾åºå¼å转
è¾å ¥å¼å转çæææ¯å¨è®¡ç®ä¹åå å°äºé¡¹å¼å转ï¼ç¶ååç¨å¾å°çæ°å¼åæ°æ®è¿è¡è®¡ç®ãå¦å¯¹äºG(X)=X+X+X2+1ï¼#ï¼ï¼å ¶æ£åå¼ä¸º1 ï¼å转å¼å为 1
è¾åºå¼å转åæ¯å°æç»å¾å°çCRCç»æå转ã
é常ï¼è¾å ¥å¼å转åçç»æå¼ä¹ä¼æ¯å转çï¼æ以è¿ä¸¤ä¸ªé项ä¸è¬æ¯ååçï¼æ们åªæå¨å¨çº¿CRC计ç®å¨ä¸ä¼çå°èªç±éæ©æ£å转çæ åµåå¨ã
é£ä¹ï¼è¿éå¼ç¨CSDNå主 bobde çä¸æ®µæ»ç»ï¼
CRCãCRCçå¤åèçæ ¡éªå¼ç计ç®æå ç¹éè¦æ¸ æ¥ï¼åªé对ä¸æ¬¡ä¸ä¸ªåèçç®æ³ï¼ï¼
1) åå§å¼ä¸ä¸º0çæ åµä¸ï¼è¯¥å¦ä½è®¡ç®ï¼
è¾å ¥æ°æ®éè¦å转ï¼å å°è¦è®¡ç®çæ°æ®ä¸åå§å¼çæä½åèè¿è¡å¼æï¼åä¸å转åçå¤é¡¹å¼è¿è¡è®¡ç®ã
è¾å ¥æ°æ®ä¸éè¦å转ï¼å å°è¦è®¡ç®çæ°æ®å·¦ç§»å°ä¸åå§å¼å¯¹é½çä½ç½®ï¼å¦CRCç®æ³ï¼å左移8ä½ï¼ä½ä½å¡«å 0ï¼å¦CRCç®æ³ï¼å左移ä½ï¼ä½ä½å¡«å 0ï¼ä¸åå§å¼è¿è¡å¼æï¼åä¸æ£å¸¸çå¤é¡¹å¼è¿è¡è®¡ç®ã
2) ç»æå¼æå¼ä¸ä¸º0çæ åµï¼ç¬¬ä¸æ¥ç®å¾å°çCRCå¼åä¸ç»æå¼æå¼è¿è¡å¼ææä½å¾å°æç»çæ ¡éªå¼ï¼
è¾åºæ°æ®å转ï¼å¦æè¾å ¥æ°æ®æ¯å转ç模å¼ï¼åç»æä¹æ¯å转ç
è¾åºæ°æ®ä¸å转ï¼å¦æè¾å ¥æ°æ®æ¯ä¸å转ç模å¼ï¼åç»æä¹æ¯ä¸å转ç
3ï¼åå§å¼çéæ©æ¯å¯èªå·±å®ä¹ï¼å¾å¤ä¸åçå家使ç¨çåå§å¼æ¯ä¸ä¸æ ·ï¼ä¸ä¸æ ·çåå§å¼å¾å°çç»æä¹æ¯ä¸ä¸æ ·çã
---------------------
åæï¼pression
foreach (string file in filenames)
{
//打开压缩文件
FileStream fs = File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(file);
entry.DateTime = DateTime.Now;
// set Size and the crc, because the information
// about the size and crc should be stored in the header
// if it is not set it is automatically written in the footer.
// (in this case size == crc == -1 in the header)
// Some ZIP programs have problems with zip files that don't store
// the size and crc in the header.
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
s.Finish();
s.Close();
}
}
}
现在再来看看解压文件类的源码
/// <summary>
/// 解压文件
/// </summary>
using System;
using System.Text;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Runtime.Serialization.Formatters.Binary;
using System.Data;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.GZip;
namespace DeCompression
{
public class UnZipClass
{
public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);
//生成解压目录
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty)
{
//解压文件到指定的目录
FileStream streamWriter = File.Create(args[1]+theEntry.Name);
int size = ;
byte[] data = new byte[];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
s.Close();
}
}
}
有了压缩和解压缩的类以后,就要在窗体里调用了。二进制matlab源码怎么?是簧片网站源码新手,不会调用?Ok,引擎搜索源码接着往下看如何在窗体里调用。
首先在窗体里放置两个命令按钮(不要告诉我你不会放啊~),mu源码 pudn然后编写以下源码
/// <summary>
/// 调用源码
/// </summary>
private void button2_Click_1(object sender,ubuntudjango源码安装 System.EventArgs e)
{
string []FileProperties=new string[2];
FileProperties[0]="C:\\unzipped\\";//待压缩文件目录
FileProperties[1]="C:\\zip\\a.zip"; //压缩后的目标文件
ZipClass Zc=new ZipClass();
Zc.ZipFileMain(FileProperties);
}
private void button2_Click(object sender, System.EventArgs e)
{
string []FileProperties=new string[2];
FileProperties[0]="C:\\zip\\test.zip";//待解压的文件
FileProperties[1]="C:\\unzipped\\";//解压后放置的目标目录
UnZipClass UnZc=new UnZipClass();
UnZc.UnZip(FileProperties);
}
好了,到此为止,如何压缩和解压缩的类都已经完成了,需要的朋友直接拿走调吧。
2024-11-23 03:03
2024-11-23 02:45
2024-11-23 02:23
2024-11-23 02:06
2024-11-23 02:03
2024-11-23 01:56
2024-11-23 00:50
2024-11-23 00:45