I need to perform certain operations with bitwise operators, let's say we have this 40 bit unsigned integer:
1071698660929
when I apply to it a OR
operator and an unsigned right shift operator I got this negative integer
Input: (1071698660929 >>> 0) | 0b0
Output: -2043163071
I noticed that as long as the number is 31 bit long I don't have any problem adding a 0B0
but when the number is greater than 31 bit it becomes negative even though I'm using the unsigned right shift operator:
32 bits binary return -1
: (0b11111111111111111111111111111111 >>> 0) | 0
31 bits binary return 2147483647
: (0b1111111111111111111111111111111 >>> 0) | 0
So I have a couple of questions:
- Why the numbers above are becoming negative if I'm using a right shift operator? What I understand is that the MAX safe integer in javascript is 53 bit long
Number.MAX_SAFE_INTEGER.toString(2).length
so I'm within the integer safe boundaries. - What could I do to make this
(1071698660929 >>> 0) | 0b0
returns1071698660929
instead of-2043163071
?