When typing these three statements in a JavaScript-Console (for example node.js)
console.log(5 & 0x5555555555555);
console.log(5 & 0x55555555555555);
console.log(5 & 0x555555555555555);
...then I get the following answers:
> console.log(5 & 0x5555555555555);
5
undefined
> console.log(5 & 0x55555555555555);
4
undefined
> console.log(5 & 0x555555555555555);
0
undefined
This seems to be very spooky: The first hexadecimal value has 13 5-digits, the last has 15 5-digits. Every three outputs should be "5" but the second and third are wrong.
Of course I want to make bit-manipulation with 64bit values (which can have up to 16 hexadecimal digits). Can anyone tell me, what my mistake is in this situation?