What does (number & number) mean? I am trying to read someone's code written in JavaScript and came over with
if(misc & 0x800) {//...} //0x800 is 2048 when converted to decimal
Where var misc = 16400; //or some other number which continuously changes
So the statement is coming like if(16400 & 2048) -do something
When I console.log()ed those two numbers I got 0 .
How does if statement works in case of number and number?
One & means, that this is bitwise AND
The numbers are
16400 (10) === 100000000010000 (2)
0x800 (16) === 100000000000 (2)
Based on bitwise operation rules The result will be:
100000000010000
100000000000
_______________
000000000000000
Such operations oftenly used for bit masks (wiki link)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With