c++ - What would a big-endian compatible version of this CRC32 method look like? -


i'm working on project requires crc32 check done on data being transmitted. make code compatible not intel architecture ("little endian"), solaris architecture ("big endian") well. i've found "ccrc32" works spiffy 2 little endian machines, utterly fails cross platform tests:

code:

ccrc32.h & ccrc32.cpp (taken off of wikipedia's "external links")

http://en.wikipedia.org/wiki/cyclic_redundancy_check

here method sample of code:

void ccrc32::partialcrc(unsigned long *ulcrc, const unsigned char *sdata, unsigned long uldatalength) { while(uldatalength--) {     //if compiler complains following line, try changing each     //occurrence of *ulcrc "((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 crc.     this->partialcrc(&ulcrc, sdata, uldatalength);     return(ulcrc ^ 0xffffffff); //finalize crc , return. } 

so question this: of big endian gurus know how tweak above methods work big endian machines, or know of existing piece of source code accomplish goal? i've been unsuccessful in search far.

thank time,

james

not sure if helps, this piece of c code has big , small endian versions.


Comments