Originally posted by Dave Jones:
I have to compare a few files to each other, the best solution is running each file through some kind of a hash algorithm, so the result will be either a hash, or a long or anything that is 16 bit long...
I though of using the CRC32 but it works with 32 bit (as implied by the name...)
Any suggestion will help. I need something simple and reliable.
Well, quite frankly, CRC32 is not reliable either -- as it is very possible to have two completely different files match because their CRC are the same.
This is true for any hash that you use. To represent, what is potentially an unlimited amount of data, in 32 bits, and expect it to be completely unique is ridiculous. The purpose of the hash is for the hash to drastically change, when only small changes are encountered -- in effect, to detect small corruptions in the file.
Anyway, if you only want 16 bits, then use the first 16 bits, or the last 16 bits, or every other bit. You'll get more different files to match, but you'll get that with any hash algorithm that you use.
Henry