0

I look for code that calculate crc32 and return int32, but I found just func that return uint or hexa or string. When I tried to convert the crc32 to int - it was too big to be int. Do you know how to calculate crc32 that return int32??

Or can you change the code in this link so - the code will return int32 instead of hexa?? http://damieng.com/blog/2006/08/08/calculating_crc32_in_c_and_net

Thanks, Chani

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Chani Poz
  • 1,413
  • 2
  • 21
  • 46
  • http://stackoverflow.com/questions/1131843/how-do-i-convert-uint-to-int-in-c – Ondrej Tucny Feb 19 '12 at 10:50
  • If I convert from uint to int it returns negative sometimes, so - Is it checksum??? maybe 2 string will return the same crc32 because of the convert. – Chani Poz Feb 19 '12 at 10:58
  • @Chanipoz CRC32 obviously has collisions, but casting to a signed int does not introduce new collisions. If you want no collisions at all, you should use a cryptographic hash with a length of at least 128 bits, but that of course doesn't fit into a `Int32`. – CodesInChaos Feb 19 '12 at 11:06

1 Answers1

5

use unchecked((Int32)someUInt32). That can return negative numbers, but that's to be expected, it's CRC32 and not CRC31 after all.

No idea why you're mentioning hex, the code you linked doesn't use hexadecimal numbers anywhere. It just uses UInt32 and byte[].

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262
  • In the link - the code return string that contains hexa like: 'cc54a3'. The UInt32 and byte[] use just in the inner func. – Chani Poz Feb 19 '12 at 11:00