Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat would a big-endian compatible version of this CRC32 method look like?
    text
    copied!<p>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:</p> <p>Code:</p> <p><a href="http://www.networkdls.com/Software.Asp?Review=22" rel="nofollow">CCRC32.h &amp; CCRC32.cpp</a> (taken off of wikipedia's "external links") </p> <p><a href="http://en.wikipedia.org/wiki/Cyclic_redundancy_check" rel="nofollow">http://en.wikipedia.org/wiki/Cyclic_redundancy_check</a></p> <p>Here is a method sample of the code:</p> <pre><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) &gt;&gt; 8) ^ this-&gt;ulTable[((*(unsigned long *)ulCRC) &amp; 0xFF) ^ *sData++]; } unsigned long CCRC32::FullCRC(const unsigned char *sData, unsigned long ulDataLength) { unsigned long ulCRC = 0xffffffff; //Initilaize the CRC. this-&gt;PartialCRC(&amp;ulCRC, sData, ulDataLength); return(ulCRC ^ 0xffffffff); //Finalize the CRC and return. } </code></pre> <p>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.</p> <p>Thank you for your time,</p> <p>James</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload