console.og(Date.now() & 0xffffffff)
I got -1798272874
which is not what I want, I want a positive integer not a negative number.
console.og(Date.now() & 0xffffffff)
I got -1798272874
which is not what I want, I want a positive integer not a negative number.
Maybe this can help you.
var date = Date.now();
var bytes = new Array();
for (i = 0; i < 4; i++) {
bytes[i] = (date >> (8*i)) & 0xff;
}
console.log(bytes);
Got the operation from here
If you zero-fill right shift (>>>
) by 0 bits, JavaScript will give you an unsigned representation of the number. So your code from above would become,
console.log((Date.now() & 0xffffffff) >>> 0)
which will result in something like 2497628378
.
See this stackoverflow question and the MDN documentation for zero-fill right shift for more information.