Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why a positive number operated with bitwise or 0 not always positive in Javascript

Why a positive number operated with bitwise or 0 not always positive in Javascript

For example:

3391700000|0
-903267296

4260919000|0
-34048296

2884900000|0
-1410067296

I'm using chrome 64-bit on Linux

related to: https://stackoverflow.com/a/12837315/1620210

like image 240
Kokizzu Avatar asked Dec 29 '25 22:12

Kokizzu


1 Answers

Because JavaScript uses 32bit integers at most, but keep in mind every number is kind of a float in this language

If you want to truncate them to an unsigned 32bit value:

(3391700000|0) >>> 0
like image 184
axelduch Avatar answered Jan 01 '26 11:01

axelduch