CRC Check Value

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. text;

Namespace Test
{
Class CRC
{
///

/// Get the CRC Check value of a byte array
///

///Byte array
/// CRC Check Value
Public static int getkey (byte [] data)
{
Int COUNT = data. length;

Byte [] buffer = new byte [data. Length + 2];

Data. copyto (buffer, 0 );

Int PTR = 0;
Int I = 0;
Int CRC = 0;
Byte crc1, crc2, crc3;

Crc1 = buffer [PTR ++];
Crc2 = buffer [PTR ++];

Buffer [count] = 0;
Buffer [count + 1] = 0;

While (-- count> = 0)
{
Crc3 = buffer [PTR ++];

For (I = 0; I {
If (crc1 & 0x80)> 7) = 1) // judge whether the high position of crc1 is 1
{
Crc1 = (byte) (crc1
If (crc2 & 0x80)> 7) = 1) // judge whether the high position of crc2 is 1
{
Crc1 = (byte) (crc1 | 0x01); // the low position of crc1 is changed from 0 to 1.
}

Crc2 = (byte) (crc2
If (crc3 & 0x80)> 7) = 1) // judge whether the high position of crc3 is 1
{
Crc2 = (byte) (crc2 | 0x01); // the low position of crc2 is changed from 0 to 1.
}

Crc3 = (byte) (crc3
Crc1 = (byte) (crc1 ^ 0x10 );

Crc2 = (byte) (crc2 ^ 0x21 );
}
Else
{
Crc1 = (byte) (crc1
If (crc2 & 0x80)> 7) = 1) // judge whether the high position of crc2 is 1
{
Crc1 = (byte) (crc1 | 0x01); // the low position of crc1 is changed from 0 to 1.
}

Crc2 = (byte) (crc2
If (crc3 & 0x80)> 7) = 1) // judge whether the high position of crc3 is 1
{
Crc2 = (byte) (crc2 | 0x01); // the low position of crc2 is changed from 0 to 1.
}

Crc3 = (byte) (crc3}
}
}

CRC = (INT) (crc1

Return CRC;
}

}< BR >}< br>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.