crc

CRC16

匿名 (未验证) 提交于 2019-12-03 00:03:02
当数据帧长度在8bits-128bits范围内时,推荐CRC-8(CRC-8能够减少额外比特的开销,且有更好的性能表现) 当数据帧长度在128bits-2048bits范围内时,推荐CRC-12,CRC-16,CRC-CCITT(CRC-12额外比特的开销更小,且用于6bit字符流的传输;对于16bits的标准,更推荐美国标准CRC-16,性能略优于CRC-CCITT); 当因数据帧长度更长、信道不稳定等情况而需要更高的性能时,CRC-32、CRC-32C将是更好的选择; CRC16的校验码是两个字节,所以Redis的源码中使用了 uint16_t类型(unsigned short int) CRC16要校验的数据位是8位 在求解CRC校验码的过程中,会用到模二除,实际我们最后不关心它的商Q(x),只关心关心余数R(x),它也是两个字节的大小 余数R(x)分为高字节RH(x)和低字节RL(x)两个部分:R(x) = RH(x) * X^8 + RL(x) (这个+,可以理解成异或,也可以理解成+号) 任何数和0异或结果还是这个数 CRC-16码由两个字节构成,在开始时CRC寄存器的每一位都预置为1 然后把CRC寄存器与8-bit的数据进行异或 之后对CRC寄存器从高到低进行移位,在最高位(MSB)的位置补零,而最低位(LSB,移位后已经被移出CRC寄存器)如果为1

JAVA之CRC校验算法

匿名 (未验证) 提交于 2019-12-02 21:53:52
用JAVA实现CRC校验。 输入byte型的数组,产生两个元素的byte型数组(也就是16位) public static byte[] makefcs(byte[] data) { int crc=0xFFFF; byte[] buf = new byte[data.length];// 存储需要产生校验码的数据 byte[] bup=new byte[2]; for (int i = 0; i < data.length; i++) { buf[i] = data[i]; //数据的复制 } int len = buf.length; for (int pos = 0; pos < len; pos++) { if (buf[pos] < 0) { crc ^= (int) buf[pos] + 256; //^异或:用于位运算,每个位相同为0,不同为1 } else { crc ^= (int) buf[pos]; } for (int i = 8; i != 0; i--) { if ((crc & 0x0001) != 0) { crc >>= 1; //右移运算符 crc ^= 0xA001; } else crc >>= 1; } } String c = Integer.toHexString(crc); if (c.length() == 4) { c = c

Fast CRC algorithm?

点点圈 提交于 2019-12-02 18:53:24
I want to create a 32 bit number out of an ASCII-string. CRC32 algorithm is exactly what I'm looking for but I can't use it because the table it requires is way too huge (it is for an embedded systems where ressources are VERY rare). So: any suggestions for a fast and slim CRC algorithm? It does not matter when collissions are a bit more probable than with the original CRC32. Thanks! CRC implementations use tables for speed. They are not required. Here is a short CRC32 using either the Castagnoli polynomial (same one as used by the Intel crc32 instruction), or the Ethernet polynomial (same one

CRC码计算及校验原理的最通俗诠释

孤街醉人 提交于 2019-12-02 10:48:39
循环冗余校验检错方案 奇偶校验码(PCC)只能校验一位错误,本节所要介绍的循环冗余校验码(CRC)的检错能力更强,可以检出多位错误。 1. CRC校验原理 CRC校验原理看起来比较复杂,好难懂,因为大多数书上基本上是以二进制的多项式形式来说明的。其实很简单的问题,其根本思想就是先在要发送的帧后面附加一个数(这个就是用来校验的校验码,但要注意,这里的数也是二进制序列的,下同),生成一个新帧发送给接收端。当然,这个附加的数不是随意的,它要使所生成的新帧能与发送端和接收端共同选定的某个特定数整除(注意,这里不是直接采用二进制除法,而是采用一种称之为“模2除法”)。到达接收端后,再把接收到的新帧除以(同样采用“模2除法”)这个选定的除数。因为在发送端发送数据帧之前就已通过附加一个数,做了“去余”处理(也就已经能整除了),所以结果应该是没有余数。如果有余数,则表明该帧在传输过程中出现了差错。 【说明】“模2除法”与“算术除法”类似,但它既不向上位借位,也不比较除数和被除数的相同位数值的大小,只要以相同位数进行相除即可。模2加法运算为:1+1=0,0+1=1,0+0=0,无进位,也无借位;模2减法运算为:1-1=0,0-1=1,1-0=1,0-0=0,也无进位,无借位。相当于二进制中的逻辑异或运算。也就是比较后,两者对应位相同则结果为“0”,不同则结果为“1”。如100101除以1110

CRC多项式转换二进制

∥☆過路亽.° 提交于 2019-12-02 05:18:11
1.多项式与二进制的直接对应关系:   X的最高次幂对应二进制的最高位数;以下各位对应多项式的各幂次,有幂次对应1,无幂次对应0;X的最高次幂是R,转换对应的二进制数R+1位; 2.多项式的生成:   发送方的接收方的约定的一个二进制数;在传输过程中始终不变。在发送方,利用生成多项式对信息多项式做模2除生成校验码,在接收方,利用生成多项式对收到的编码多项式做模2除检测和确定错误位置。   应满足:a、生成多项式的最高位和最低位必须为1。       b、当被传送信息(CRC码)任何一位发生错误时,被生成多项式做模2除后应该使余数不为0。       c、不同位发生错误时,应该使余数不同。       d、对余数继续做模2除,应使余数循环 来源: https://www.cnblogs.com/zhangweigang/p/11731572.html

generating an safe hashcode for an objectgraph

独自空忆成欢 提交于 2019-12-01 23:03:09
I am importing some data from an file (xls, csv, xml) wich will result in a complex in-memory object graph. Now I need to know whether this graph has been modified since it once was exported. What would be a safe way to check this? I suppose I'd export a hashcode with the file? If so would the standard way of generating an object's hashcode suffice? How should I generate the hash? I would prefer to generate the hash on the object graph rather than on the actual stream/file. You can ensure that nobody changes your data by encrypting it or using a hashcode. In case of the text based formats you

MFC添加拖动文件事件处理函数(二)

∥☆過路亽.° 提交于 2019-12-01 10:05:41
这里列举对于函数的处理---读取文件个数,并逐个计算每个文件的crc值。 代码如下: 1 void CFile_DemoDlg::OnDropFiles(HDROP hDropInfo) 2 { 3 // TODO: 在此添加消息处理程序代码和/或调用默认值 4 UINT fileCount; 5 WORD crc,n; 6 BYTE szchar[201], crc_hex[4], bt; 7 CString strtmp; 8 TCHAR file_name[MAX_PATH] = { 0 }; 9 //get number of drop files. 10 fileCount = DragQueryFile(hDropInfo,0xffffffff,NULL,0); 11 for (UINT i = 0; i < fileCount; i++) 12 { 13 DragQueryFile(hDropInfo,i,file_name,MAX_PATH-1);//get the file name of the i-th file 14 CFile file(file_name,CFile::modeRead);//open the file 15 UpdateData(true); 16 m_path += file.GetFilePath(); 17 m_path += "

XAPK File validation shows in correct data Information

六月ゝ 毕业季﹏ 提交于 2019-12-01 03:53:23
While running APK expansion file sample I just skiped checking CRC32 to avoide crc bug algorithm and its working very fine!! But while XAPK File validation shows in correct downloaded data information 99% !!, how to avoid that and view full 100% by hard-coding? It's not a best sloution but I got the solution by hard coding the ProgressBar mPB; TextView mProgressPercent; TextView mProgressFraction; in DownloaderActivity onPostExecute method of validationAsynctask mPB.setMax(10); mPB.setProgress(100); mProgressPercent.setText(100 + "%"); mProgressFraction.setText("Download Completed Successfully

XAPK File validation shows in correct data Information

[亡魂溺海] 提交于 2019-12-01 00:34:55
问题 While running APK expansion file sample I just skiped checking CRC32 to avoide crc bug algorithm and its working very fine!! But while XAPK File validation shows in correct downloaded data information 99% !!, how to avoid that and view full 100% by hard-coding? 回答1: It's not a best sloution but I got the solution by hard coding the ProgressBar mPB; TextView mProgressPercent; TextView mProgressFraction; in DownloaderActivity onPostExecute method of validationAsynctask mPB.setMax(10); mPB

Need help in correcting issues in CRC-ITU check method written in Javascript (node.js)

为君一笑 提交于 2019-11-30 22:23:11
We are trying to code GPS device listener on Javascript. While doing this, we are unable to develop the right script for the CRC-ITU error check. The explanation for the crc code generation from protocol document is as below A check code may be used by the terminal or the server to distinguish whether the received information is error or not. To prevent errors occur during data transmission, error check is added to against data misoperation, so as to increase the security and efficiency of the system. The check code is generated by the CRC-ITU checking method. The check codes of data in the