Problem with big array of bytes that not can convert the CRC Value to unsigned integer #22
	
		Labels
		
	
	
	
	
	
	
		No Milestone
		
			
		
	
	
		
		
		
			No project
			
				
			
		
	
	
	
	
	
		No Assignees
		
			
		
	
	
	
		1 Participants
		
	
	
		
		
			Notifications
			
				
			
		
	
	
	
	Due Date
	No due date set.
			
				Dependencies
				
				
		
	
	
	No dependencies set.
			Reference: sheetjs/js-crc32#22
			
		
	
		Loading…
	
		Reference in New Issue
	
	Block a user
	
	No description provided.
		
		Delete Branch "%!s()"
	 
	Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I have a byte array that i trying to do CRC sum on and i getting a signed Integer as the library describe but when i try to convert the signed integer to a unsigned integer i get the same value
Here is a example where i put in a array of integers and gets crcValue = 1070418610 in the console:
var crcValue = CRC32.buf([0, 128, 0, 1, 35, 91, 123, 34, 73, 115, 69, 109, 112, 116, 121, 34, 58, 102, 97, 108, 115, 101, 44, 34, 88, 34, 58, 50, 56, 50, 44, 34, 89, 34, 58, 55, 52, 53, 125, 93]); console.log('crcValue', crcValue);and here i try to convert between signed and unsigned 32-bit integers and get the same value back 1070418610:
var crcValue = CRC32.buf([0, 128, 0, 1, 35, 91, 123, 34, 73, 115, 69, 109, 112, 116, 121, 34, 58, 102, 97, 108, 115, 101, 44, 34, 88, 34, 58, 50, 56, 50, 44, 34, 89, 34, 58, 55, 52, 53, 125, 93]) >>> 0; console.log('crcValue', crcValue);but if i make a small array it works like this returnes -1950775789:
var crcValue = CRC32.buf([0, 1, 2, 3]); console.log('crcValue', crcValue);and this returns 2344191507:
var crcValue = CRC32.buf([0, 1, 2, 3]) >>> 0; console.log('crcValue', crcValue);What is wrong with the big array?
The behavior is correct.
There are two types of 32-bit integers that JS specifies:
"signed 32-bit integers": the integer range is
-(2**31) ... 2**31 - 1(-2147483648 ... 2147483647). Operators like|and&always coerce to signed 32-bit integers. For example,4000000000|0is-294967296"unsigned 32-bit integers": the integer range is
0 ... 2**32 - 1(0 ... 4294967295). The operator>>>always returns an unsigned 32-bit integer. For example,(-1)>>>0is4294967295.Integers in the range
0 ... 2**31-1(0 ... 2147483647) have the same bit representation as signed 32-bit integer and unsigned 32-bit integer, so| 0won't negate them and>>> 0won't change the result.1070418610is in that range and thus won't be changed.