P89lpc9xx CRC Calculation

Source: Internet
Author: User

Used to verify the data in the sector. Read sector CRC is correct only after many effortsAlgorithm:

 

Unsigned long distrined (unsigned char data)
{
Unsigned long tap,;
Unsigned char data2;
Tap = 0;

Data2 = data <7;
A = data2> 7;
A = A <0;
Tap = tap |;

Data2 = (Data <(8-1-1 ));
A = data2> 7;
A = A <3;
Tap = tap |;

Data2 = (Data <(8-2-1 ));
A = data2> 7;
A = A <5;
Tap = tap |;

Data2 = (Data <(8-3-1 ));
A = data2> 7;
A = A <8;
Tap = tap |;

Data2 = (Data <(8-4-1 ));
A = data2> 7;
A = A <10;
Tap = tap |;

Data2 = (Data <(8-5-1 ));
A = data2> 7;
A = A <13;
Tap = tap |;

Data2 = (Data <(8-6-1 ));
A = data2> 7;
A = A <16;
Tap = tap |;

Data2 = (Data <(8-7-1 ));
A = data2> 7;
A = A <18;
Tap = tap |;

Return tap;
}

Unsigned long CRC32 (unsigned char * buffer, int Len)
{
Unsigned long CRC, tap, crc_flag;
Int I;
Unsigned char B;

CRC = 0;
Tap = 0;
Crc_flag = 0;

For (I = 0; I <Len; I ++ ){
B = buffer [I];

Crc_flag = CRC> 31;
CRC = CRC <1;

Tap = distribute (B );

CRC = CRC ^ tap;

If (crc_flag = 0 ){
}
Else {
CRC = CRC ^ 0x00400007;
}
}

Return CRC;
}

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.