crc16

Calculating CRC16 in C#

三世轮回 提交于 2021-02-11 15:38:55
问题 I'm trying to port an old code from C to C# which basically receives a string and returns a CRC16 of it... The C method is as follow: #define CRC_MASK 0x1021 /* x^16 + x^12 + x^5 + x^0 */ UINT16 CRC_Calc (unsigned char *pbData, int iLength) { UINT16 wData, wCRC = 0; int i; for ( ;iLength > 0; iLength--, pbData++) { wData = (UINT16) (((UINT16) *pbData) << 8); for (i = 0; i < 8; i++, wData <<= 1) { if ((wCRC ^ wData) & 0x8000) wCRC = (UINT16) ((wCRC << 1) ^ CRC_MASK); else wCRC <<= 1; } }

Calculating CRC16 in C#

▼魔方 西西 提交于 2021-02-11 15:38:44
问题 I'm trying to port an old code from C to C# which basically receives a string and returns a CRC16 of it... The C method is as follow: #define CRC_MASK 0x1021 /* x^16 + x^12 + x^5 + x^0 */ UINT16 CRC_Calc (unsigned char *pbData, int iLength) { UINT16 wData, wCRC = 0; int i; for ( ;iLength > 0; iLength--, pbData++) { wData = (UINT16) (((UINT16) *pbData) << 8); for (i = 0; i < 8; i++, wData <<= 1) { if ((wCRC ^ wData) & 0x8000) wCRC = (UINT16) ((wCRC << 1) ^ CRC_MASK); else wCRC <<= 1; } }

CRC-ITU calculation in c#

不问归期 提交于 2021-02-07 04:12:06
问题 I'm new to C#. I need to calculate CRC-ITU for the packet recieved from GPS devices. There is C code provided in the documentation but i don't know how to port it to C#, anyone could help me? here is CRC-ITU algorithm in C : static const U16 crctab16[] = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64,

CRC-ITU calculation in c#

爱⌒轻易说出口 提交于 2021-02-07 04:10:42
问题 I'm new to C#. I need to calculate CRC-ITU for the packet recieved from GPS devices. There is C code provided in the documentation but i don't know how to port it to C#, anyone could help me? here is CRC-ITU algorithm in C : static const U16 crctab16[] = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64,

CRC-ITU calculation in c#

倖福魔咒の 提交于 2021-02-07 04:08:26
问题 I'm new to C#. I need to calculate CRC-ITU for the packet recieved from GPS devices. There is C code provided in the documentation but i don't know how to port it to C#, anyone could help me? here is CRC-ITU algorithm in C : static const U16 crctab16[] = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64,

CRC-ITU calculation in c#

て烟熏妆下的殇ゞ 提交于 2021-02-07 04:06:30
问题 I'm new to C#. I need to calculate CRC-ITU for the packet recieved from GPS devices. There is C code provided in the documentation but i don't know how to port it to C#, anyone could help me? here is CRC-ITU algorithm in C : static const U16 crctab16[] = { 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64,

CRC16 (ModBus) - computing algorithm

家住魔仙堡 提交于 2021-02-04 19:44:27
问题 I am using the ModBus RTU, and I'm trying to figure out how to calculate the CRC16. I don't need a code example. I am simply curious about the mechanism. I have learned that a basic CRC is a polynomial division of the data word, which is padded with zeros, depending on the length of the polynomial. The following test example is supposed to check if my basic understanding is correct: data word: 0100 1011 polynomial: 1001 (x 3 +1) padded by 3 bits because of highest exponent x 3 calculation:

Verification of a CRC checksum against zero

和自甴很熟 提交于 2021-01-07 01:30:46
问题 I had some contact with the CRC-16 checksum in the past and was accustomed to verifying it by recalculating the CRC-16 checksum over the file I want to verify, plus the 2 bytes of the CRC-16 itself. If the result was zero, then the file integrity was valid, otherwise not. This can be coded very efficiently like with the following pseudo-C: if (recalculated_crc16_checksum != 0) // Error: file integrity is corrupt else // Success: file integrity is valid I recently wanted to use the CRC-32

crc-16 cccitt problem - incorrect calculation

北城以北 提交于 2020-07-09 14:31:50
问题 Trying to implement this CRC16 CITT checksum within my bluetooth ios mobile application: extension Data { typealias bit_order_16 = (_ value: UInt16) -> UInt16 typealias bit_order_8 = (_ value: UInt8) -> UInt8 func crc16Check() -> UInt16 { let data = self as! NSData let bytes = UnsafePointer<UInt8>(data.bytes.assumingMemoryBound(to: UInt8.self)) let length = data.length return crc16ccitt(message: bytes, nBytes: length) } func straight_16(value: UInt16) -> UInt16 { return value } func reverse