crc

checksum calculation

感情迁移 提交于 2019-12-07 06:58:28
To calculate CRC I found a piece of code but I am not understanding the concept. Here is the code: count =128 and ptr=some value; calcrc(unsigned char *ptr, int count) { unsigned short crc; unsigned char i; crc = 0; while (--count >= 0) { crc = crc ^ (unsigned short)*ptr++ << 8; i = 8; do { if (crc & 0x8000) crc = crc << 1 ^ 0x1021; else crc = crc << 1; } while(--i); } return (crc); } Please any body explain and tell me the logic. This looks like a CRC (specifically it looks like CRC-16-CCITT, used by things like 802.15.4, X.25, V.41, CDMA, Bluetooth, XMODEM, HDLC, PPP and IrDA). You might

compute CRC of struct in Python

ⅰ亾dé卋堺 提交于 2019-12-07 06:10:29
问题 I have the following struct, from the NRPE daemon code in C: typedef struct packet_struct { int16_t packet_version; int16_t packet_type; uint32_t crc32_value; int16_t result_code; char buffer[1024]; } packet; I want to send this data format to the C daemon from Python. The CRC is calculated when crc32_value is 0 , then it is put into the struct. My Python code to do this is as follows: cmd = '_NRPE_CHECK' pkt = struct.pack('hhIh1024s', 2, 1, 0, 0, cmd) # pkt has length of 1034, as it should

Understanding two different ways of implementing CRC generation with LFSR

微笑、不失礼 提交于 2019-12-06 09:09:33
问题 There are two ways of implementing CRC generation with linear feedback shift registers (LFSR), as shown in this figure . The coefficients of generator polynomial in this picture are 100111, and the red "+" circles are exclusive-or operators. The initialization register values are 00000 for both. For example, if the input data bit stream is 10010011, both A and B will give CRC checksum of 1010. The difference is A finishes with 8 shifts, while B with 8+5=13 shifts because of the 5 zeros

Improve speed on Crc16 calculation

我的未来我决定 提交于 2019-12-06 07:49:24
I need to calculate Crc16 checksums with a $1021 polynom over large files, below is my current implementation but it's rather slow on large files (eg a 90 MB file takes about 9 seconds). So my question is how to improve my current implementation (to make it faster), I have googled and looked at some samples implementing a table lookup but my problem is that I don't understand how to modify them to include the polynom (probably my math is failing). { based on http://miscel.dk/MiscEl/CRCcalculations.html } function Crc16(const Buffer: PByte; const BufSize: Int64; const Polynom: WORD=$1021; const

CRC-CCITT (0xFFFF) function?

让人想犯罪 __ 提交于 2019-12-06 03:35:54
问题 Can someone help me with Delphi implementation of CRC-CCITT ( 0xFFFF )? Already get the Java version, but confusing on how to port it to Delphi public static int CRC16CCITT(byte[] bytes) { int crc = 0xFFFF; // initial value int polynomial = 0x1021; // 0001 0000 0010 0001 (0, 5, 12) for (byte b : bytes) { for (int i = 0; i < 8; i++) { boolean bit = ((b >> (7-i) & 1) == 1); boolean c15 = ((crc >> 15 & 1) == 1); crc <<= 1; if (c15 ^ bit) crc ^= polynomial; } } crc &= 0xffff; //System.out.println

Best 8-bit supplemental checksum for CRC8-protected packet

别说谁变了你拦得住时间么 提交于 2019-12-06 03:03:32
I'm looking at designing a low-level radio communications protocol, and am trying to decide what sort of checksum/crc to use. The hardware provides a CRC-8; each packet has 6 bytes of overhead in addition to the data payload. One of the design goals is to minimize transmission overhead. For some types of data, the CRC-8 should be adequate, for for other types it would be necessary to supplement that to avoid accepting erroneous data. If I go with a single-byte supplement, what would be the pros and cons of using a CRC8 with a different polynomial from the hardware CRC-8, versus an arithmetic

C# CRC16 modbus

对着背影说爱祢 提交于 2019-12-05 23:14:11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WaterBubbleCheck { public class Crc { /// <summary> /// 判断数据中crc是否正确 /// </summary> /// <param name="datas">传入的数据后两位是crc</param> /// <returns></returns> public static bool IsCrcOK(byte[] datas) { int length = datas.Length-2; byte[] bytes = new byte[length]; Array.Copy(datas, 0, bytes, 0, length); byte[] getCrc = GetModbusCrc16(bytes); if(getCrc[0]== datas[length]&&getCrc[1]==datas[length+1]) { return true; } else { return false; } } /// <summary> /// 传入数据添加两位crc /// <

CRC16 in Python

你离开我真会死。 提交于 2019-12-05 20:30:14
How do I calculate CRC16 in Python? In Perl I would write something like: use Digest::CRC "crc16"; $result = crc16($str); How do I do same thing in Python? There is a library for calculating CRC16 here http://pypi.python.org/pypi/crc16/0.1.0 来源: https://stackoverflow.com/questions/5292290/crc16-in-python

Checking the error detection capabilities of CRC polynomials

孤者浪人 提交于 2019-12-05 14:32:46
I tried to find out how to calculate the error detection capabilities of arbitrary CRC polynomials. I know that there are various error detection capabilities that may (or may not) apply to an arbitrary polynomial: Detection of a single bit error: All CRCs can do this since this only requires a CRC width >= 1. Detection of burst errors: All CRCs can detect burst errors up to a size that equals their width. Detection of odd numbers of bit errors: CRC with polynomials with an even number of terms (which means an even number of 1-bits in the full binary polynomial) can do this. Detection of

compute CRC of struct in Python

牧云@^-^@ 提交于 2019-12-05 08:33:24
I have the following struct, from the NRPE daemon code in C: typedef struct packet_struct { int16_t packet_version; int16_t packet_type; uint32_t crc32_value; int16_t result_code; char buffer[1024]; } packet; I want to send this data format to the C daemon from Python. The CRC is calculated when crc32_value is 0 , then it is put into the struct. My Python code to do this is as follows: cmd = '_NRPE_CHECK' pkt = struct.pack('hhIh1024s', 2, 1, 0, 0, cmd) # pkt has length of 1034, as it should checksum = zlib.crc32(pkt) & 0xFFFFFFFF pkt = struct.pack('hhIh1024s', 2, 1, checksum, 0, cmd) socket