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

Closed
opened 2017-12-07 07:47:24 +00:00 by ikarius6 · 1 comment
ikarius6 commented 2017-12-07 07:47:24 +00:00 (Migrated from github.com)

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

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 commented 2017-12-07 08:03:16 +00:00 (Migrated from github.com)

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;
It's mentioned in the [README](https://github.com/sheetjs/js-crc32#usage): > The return value is a signed 32-bit integer. This decision was made [for performance reasons](https://github.com/SheetJS/js-crc32/issues/4#issuecomment-170050796). 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: <img width="216" alt="jscrc32" src="https://user-images.githubusercontent.com/24845478/33704393-4d75e930-dafa-11e7-9504-320c48a4091f.png"> That output is generated [as follows](https://github.com/SheetJS/js-crc32/blob/master/demo/browser.flow.js#L43-L45): ```js var txt = document.getElementById('rawdata'); var crc32_signed = X.str(txt.value); var crc32_unsigned = crc32_signed >>> 0; ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/js-crc32#10
No description provided.