I'm working on a project that requires a CRC32 check to be done on data that is being transmitted. I would like to make my code compatible for not only Intel architecture ("Little Endian"), but for Solaris architecture ("Big Endian") as well. I've found this "CCRC32" that works spiffy for two little endian machines, but utterly fails any cross platform tests:
Code:
CCRC32.h & CCRC32.cpp (taken off of wikipedia's "external links")
http://en.wikipedia.org/wiki/Cyclic_redundancy_check
Here is a method sample of the code:
void CCRC32::PartialCRC(unsigned long *ulCRC, const unsigned char *sData, unsigned long ulDataLength) {
while(ulDataLength--) {
//If your compiler complains about the following line, try changing each
//occurrence of *ulCRC with "((unsigned long)*ulCRC)" or "*(unsigned long *)ulCRC".
*(unsigned long *)ulCRC =
((*(unsigned long *)ulCRC) >> 8)
^ this->ulTable[((*(unsigned long *)ulCRC) & 0xFF) ^ *sData++];
}
unsigned long CCRC32::FullCRC(const unsigned char *sData, unsigned long ulDataLength) {
unsigned long ulCRC = 0xffffffff; //Initilaize the CRC.开发者_高级运维
this->PartialCRC(&ulCRC, sData, ulDataLength);
return(ulCRC ^ 0xffffffff); //Finalize the CRC and return.
}
So my question is this: Do you any of you big endian gurus know how to tweak the above methods to work with big endian machines, or does anyone know of an existing piece of source code that could accomplish my goal? I've been unsuccessful in my search thus far.
Thank you for your time,
James
Not sure if it helps, but this piece of C code has big and small endian versions.
精彩评论