So I've recently implemented ROM IEEE CRC-32 calculation in hardware for my VeriNES. It actually works perfectly and all the ROMs I've tested all have identical CRCs to that of BootGod's NesCartDB. So this isn't really a debugging-type question since i have it working - it's more of a curiosity that I'd like to make some sense of.
When I first implemented the CRC module in my hardware the CRCs were totally incorrect. After doing some research online I realized that I should have been reversing my data input to my CRC calculator. As far as I can tell this has to do with the fact that the data words of say, an Ethernet packet, are put on the wire MSbit first. So each bit is shifted into the CRC calculation routine MSbit first. I think some CRC-32 algo implementations simply reverse the polynomial itself which results in the same effect (at least I think that's why).
However, even after I reversed the data input to the CRC module my answers were still wrong. Then I thought to myself, "hey, maybe I need to reverse the CRC back again since if we use the "wire" metaphor then the data would be coming to me MSbit first" (since that's how it was originally sent/input). So I did that and the answer was still wrong!
But fortunately, BootGod had emailed me some of his CRC code and told me to make sure that I XOR'ed the final CRC result with 0xFFFFFFFF (this is the same as just inverting every bit). Once I did that I _finally_ got the right answer.
So I have 2 questions:
1) Is my interpretation of putting the data bits on the wire MSbit first correct (i.e. the reason I need to reverse the data input and then reverse the resulting CRC output)?
2) Why in the heck do I need to invert the resulting CRC before I get the correct answer? In my CRC research on other sites I've actually seen both types of solutions - that is, some people invert the CRC result and some just plain don't. It's weird, it's like no one really knows whether they should or not.
Anyway, thanks in advance for any input.
Pz
Jonathon
When I first implemented the CRC module in my hardware the CRCs were totally incorrect. After doing some research online I realized that I should have been reversing my data input to my CRC calculator. As far as I can tell this has to do with the fact that the data words of say, an Ethernet packet, are put on the wire MSbit first. So each bit is shifted into the CRC calculation routine MSbit first. I think some CRC-32 algo implementations simply reverse the polynomial itself which results in the same effect (at least I think that's why).
However, even after I reversed the data input to the CRC module my answers were still wrong. Then I thought to myself, "hey, maybe I need to reverse the CRC back again since if we use the "wire" metaphor then the data would be coming to me MSbit first" (since that's how it was originally sent/input). So I did that and the answer was still wrong!
But fortunately, BootGod had emailed me some of his CRC code and told me to make sure that I XOR'ed the final CRC result with 0xFFFFFFFF (this is the same as just inverting every bit). Once I did that I _finally_ got the right answer.
So I have 2 questions:
1) Is my interpretation of putting the data bits on the wire MSbit first correct (i.e. the reason I need to reverse the data input and then reverse the resulting CRC output)?
2) Why in the heck do I need to invert the resulting CRC before I get the correct answer? In my CRC research on other sites I've actually seen both types of solutions - that is, some people invert the CRC result and some just plain don't. It's weird, it's like no one really knows whether they should or not.
Anyway, thanks in advance for any input.
Pz
Jonathon