Skip to content
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

Why never gives the same result than others crc32? #10

Closed
ikarius6 opened this issue Dec 7, 2017 · 1 comment
Closed

Why never gives the same result than others crc32? #10

ikarius6 opened this issue Dec 7, 2017 · 1 comment

Comments

@ikarius6
Copy link

ikarius6 commented Dec 7, 2017

I was trying with a single string and im getting wierd result with negative numbers...

https://www.functions-online.com/crc32.html
4ff9fc6e4e5d5f590c4f2134a8cc96d1 = 3264575876

Your code:
-1030391420

@reviewher
Copy link

It's mentioned in the README:

The return value is a signed 32-bit integer.

This decision was made for performance reasons.

The website you linked is giving you the unsigned value. If you want to convert to unsigned, use an unsigned right shift: (-1030391420) >>> 0 == 3264575876 will give you the correct value.

Note: The web demo http://oss.sheetjs.com/js-crc32/ includes both forms:

jscrc32

That output is generated as follows:

var txt = document.getElementById('rawdata');
var crc32_signed = X.str(txt.value);
var crc32_unsigned = crc32_signed >>> 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants