1

CRC32 is calculated as uint32, while HashAlgorithm in .NET by convention returns byte[]. I can, of course, easily convert it with bytes = BitConverter.GetBytes(hash) but this is affected by "endianness" of a system (almost no chance for big-endian, of course).

Anyway, I've been thinking is there any convention to follow? I have a feeling that it should be big-endian to make hash.ToString("X") and bytes.ToHex() (assuming .ToHex() exists) look the same.

I've checked https://github.com/vurdalakov/crc32/wiki/CRC32 and it does not do that. Any thoughts?

Milosz Krajewski
  • 1,160
  • 1
  • 12
  • 19

1 Answers1

0

I can only cite examples, where the zip and gzip file formats store the CRC in little-endian order. I'm sure someone can find examples where a 32-bit CRC is stored in big-endian order, sometimes called "network order" as big-endian is intended to be a convention for network communications.

If you are defining your own protocol, then you can pick whichever you like. For the code to be portable, you would need to use shift operators to pick apart the bytes so that the endianess of the machine does not affect the result.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158