Προς το περιεχόμενο

crc 32bit σε c


sattip

Προτεινόμενες αναρτήσεις

Δημοσ.

προσπαθω να υλοποιισω ενα προγραμμα υπολογισμου crc σε c.

 

#include<stdlib.h>

#include<stdio.h>

#include<math.h>

#include <stdint.h>

#define POLYNOMIAL 0x04C11DB7

#define FINAL_XOR_VALUE 0xFFFFFFFF

 

/*

* The width of the CRC calculation and result.

* Modify the typedef for a 16 or 32-bit CRC standard.

*/

typedef uint32_t crc;

 

#define WIDTH (8 * sizeof(crc))

#define TOPBIT (1 << (WIDTH - 1))

int main() {

 

crcSlow("229",3);

 

system("pause");

}

 

crcSlow(uint32_t const message[], int nBytes)

{

crc remainder = 0xFFFFFFFF;

int byte;

 

/*

* Perform modulo-2 division, a byte at a time.

*/

for ( byte = 0; byte < nBytes; ++byte)

{

/*

* Bring the next byte into the remainder.

*/

remainder ^= (message[byte] << (WIDTH - 8));

 

/*

* Perform modulo-2 division, a bit at a time.

*/

uint32_t bit;

for ( bit =8 ; bit > 0; --bit)

{

/*

* Try to divide the current data bit.

*/

if (remainder & TOPBIT)

{

remainder = (remainder << 1) ^ POLYNOMIAL;

}

else

{

remainder = (remainder << 1);

}

}

}

 

/*

* The final remainder is the CRC result.

*/

printf("%d\n",remainder);

return (remainder^FINAL_XOR_VALUE);

 

 

} /* crcSlow() */

 

εχω τον παραπανω κωδικα αλλα στο τελοσ μου εμφανιζει ενα νουμερο δεκαδικο που αν το μετατρεψω σε δεκαεξαδικο δεν εχει καμια σχεση το αποτελεσμα του crc32bit.οπωσ θα δειτε και στον κωδικα υλοποιω την modulo-2 διαιρεση με το πολυονημο του crc32.ευχαριστω για την βοηθεια σας.

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...