Giving -ve CheckSum for formData. #2

Closed
opened 2017-05-08 07:01:58 +00:00 by deepak4u2006 · 2 comments
deepak4u2006 commented 2017-05-08 07:01:58 +00:00 (Migrated from github.com)

Hi I am using this library in my current project. It gives perfect checksum for the Test Strings, but in my real scenario I need to calculate the checksum of my formdata.
A typical formdata will be like;
var ADLER32 = require('adler-32'); let checkSum = ADLER32.str("formdata={\"data\":\"value\", \"key\":\"value1\", \"key2\":\"value2\"}123456");

I get a negative checksum for this input. -1415900241

for let checkSum = ADLER32.str("SheetJS");
I get proper checksum Value. 176947863

Hoping to get a solution !!!

Hi I am using this library in my current project. It gives perfect checksum for the Test Strings, but in my real scenario I need to calculate the checksum of my formdata. A typical formdata will be like; `var ADLER32 = require('adler-32'); let checkSum = ADLER32.str("formdata={\"data\":\"value\", \"key\":\"value1\", \"key2\":\"value2\"}123456");` I get a negative checksum for this input. **-1415900241** for `let checkSum = ADLER32.str("SheetJS");` I get proper checksum Value. **176947863** Hoping to get a solution !!!
SheetJSDev commented 2017-05-08 07:08:20 +00:00 (Migrated from github.com)

@deepak4u2006 it is explained in the README:

The return value is a signed 32-bit integer.

If you need the unsigned value, convert to unsigned integer with >>>0:

var ADLER32 = require('adler-32');
let checkSum = ADLER32.str("formdata={\"data\":\"value\", \"key\":\"value1\", \"key2\":\"value2\"}123456") >>> 0;

Note that the web demo displays both types: http://oss.sheetjs.com/js-adler32/

adler32sign

That page uses the >>>0 trick to generate the unsigned value

@deepak4u2006 it is explained in the README: > The return value is a signed 32-bit integer. If you need the unsigned value, convert to unsigned integer with `>>>0`: ```js var ADLER32 = require('adler-32'); let checkSum = ADLER32.str("formdata={\"data\":\"value\", \"key\":\"value1\", \"key2\":\"value2\"}123456") >>> 0; ``` Note that the web demo displays both types: http://oss.sheetjs.com/js-adler32/ <img width="407" alt="adler32sign" src="https://cloud.githubusercontent.com/assets/6070939/25793598/49e9b654-339b-11e7-953e-c76e1b237707.png"> [That page uses the `>>>0` trick to generate the unsigned value](https://github.com/SheetJS/js-adler32/blob/master/demo/browser.flow.js#L43-L45)
deepak4u2006 commented 2017-05-08 07:21:46 +00:00 (Migrated from github.com)

@SheetJSDev Thanks for the quickest reply ever possible.
adding >>>0 worked like a dream.

Thanks again!!! 👍

@SheetJSDev Thanks for the quickest reply ever possible. adding `>>>0` worked like a dream. Thanks again!!! :+1:
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-adler32#2
No description provided.