New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrong return value from crc32()? #5
Comments
EDIT: This is not a bug. The number returned by crc32 is a Number, not a hexstring. Try doing this: (require('crc').crc32('alejandro') + Math.pow(2, 32) ).toString(16);
'aac5a14f' or this... require('crc').hex32(require('crc').crc32('alejandro') );
'AAC5A14F' Please close this issue |
I wasn't actually talking about the hex string equivalent at all. My problem was basic checksum comparison on a numeric level (using plain ===, without converting to a string in any base). I didn't realize until I saw your usage here that you were returning a signed int instead of an unsigned one. This is a bit of an unusual return type based on other crc32 libs I've used (eg http://www.wolframalpha.com/input/?i=crc32+%22alejandro%22 ), which makes basic checksum comparison fail, if one of the checksums comes from a different library/language. I'm guessing you did this to get all 32 bits of the javascript's puny "Number"? That makes sense. Anyway, I'll close it because it works, but you might want to document this. I banged my head on it for a while before switching libraries. |
@cainus - Agreed 100%. This should definitely be documented. The other CRC functions (the ones less than 32-bits) return unsigned values. JavaScript's "Number" should be more than capable of handling a 32-bit unsigned value. Maybe this should be changed (perhaps by adding 2^32 to the result)? Maybe re-open this issue so this can be documented??? |
This should be "AAC5A14F" or 2865078607 as far as my testing in other languages goes.
This package appears to get it right too: https://npmjs.org/package/crc32
FYI: I'm on 64-bit node. v 0.8.3
The text was updated successfully, but these errors were encountered: