I'm searching to calculate CRC-16 for concox VTS. After search a lot I've got several formula, lookup table, CRC32.net library etc and tried them. But didn't get the actual result which I've wanted.
For example, when I use crc32.net library :
byte[] data = { 11, 01, 03, 51, 51, 00, 94, 10, 95, 20, 20, 08, 25, 81, 00, 23 };
UInt32 crcOut = Crc32Algorithm.ComputeAndWriteToEnd(data);
Console.WriteLine(crcOut.ToString());
It returns : 3232021645
But actually it should return : 90DD
I've tried another example too but they also did not return proper value.
Edit :
Here is the RAW data from Device :
{78}{78}{11}{01}{03}{51}{51}{00}{94}{10}{95}{20}{20}{08}{25}{81}{00}{23}{90}{DD}{0D}{0A}
When split by following data sheet, it looks like -
{78}{78} = Start Bit
{11} = Packet Length(17) = (01 + 12 + 02 + 02) = Decimal 17 = Hexadecimal 11
{01} = Protocol No
{03}{51}{51}{00}{94}{10}{95}{20} = TerminalID = 0351510094109520
{20}{08} = Model Identification Code
{25}{81} = Time Zone Language
{00}{23} = Information Serial No
{90}{DD} = Error Check (CRC : Packet Length to Information Serial No)
{0D}{0A} = Stop Bit
They told in error check it need CRC from Packet Length to Information Serial No. To make reply this packet I also need to make a data packet with CRC code.
I've found an online calculator from below link. The data match with CRC-16/X-25.
Now I need to calculate it by C# code.
Waiting for your reply.
Thanks
The CRC-16 you assert that you need in your comment (which needs to be in your question) is the CRC-16/X-25. On your data, that CRC gives 0xcac0
, not 0x90dd
.
In fact, none of the documented CRC-16's listed in that catalog produce 0x90dd
for your data. You need to provide a reference for the CRC that you need, and how you determined that 0x90dd
is the expected result for that data.
Update for updated question:
The bytes you provided in your example data are in decimal:
byte[] data = { 11, 01, 03, 51, 51, 00, 94, 10, 95, 20, 20, 08, 25, 81, 00, 23 };
That is completely wrong, since, based on the actual data message data in your updated question that you want the CRC for, those digits must be interpreted as hexadecimal. (Just by chance, none of those numbers have hexadecimal digits in a
..f
.) To represent that test vector in your code correctly, it needs to be:
byte[] data = { 0x11, 0x01, 0x03, 0x51, 0x51, 0x00, 0x94, 0x10, 0x95, 0x20, 0x20, 0x08, 0x25, 0x81, 0x00, 0x23 };
This computes the CRC-16/X-25:
ushort crc16_x25(byte[] data, int len) {
ushort crc = 0xffff;
for (int i = 0; i < len; i++) {
crc ^= data[i];
for (unsigned k = 0; k < 8; k++)
crc = (crc & 1) != 0 ? (crc >> 1) ^ 0x8408 : crc >> 1;
}
return ~crc;
}