What are bitwise operations?
bitwise-operators, java
Solution
& is bitwise operator whereas && is conditional operator.You are playing with bitwise operator.
The AND operator specifies that both Signals A and B must be charged for the result to be charged. Therefore, AND-ing the bytes 10 and 6 results in 2, as follows:
a = 0000 1010 (10)
b = 0000 0110 (6)
---- ----
r = 0000 0010 (2) // a&b
See here for more examples:
Bitwise and Bit Shift Operators
~ Unary bitwise complement
<< Signed left shift
>> Signed right shift
>>> Unsigned right shift
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise inclusive OR
Problem
I'm in the middle of studying the book named Beginning Android Games. One thing that I noticed was this: ``` int action = event.getAction() & MotionEvent.ACTION_MASK; int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; ``` This is the firsr time I've seen a variables like that so I don't know what it does. I ran the code in java and created some sample. If I run this code: ``` int i = 10 >> 500; System.out.print("Answer " + i); ``` The answer would be 0? Why is that? And if I run this code: ``` int i = 10 & 500; System.out.print("Answer " + i); ``` At first I thought it was concatenation of value so I would assume that i = 10500 but thats not the case. The answer is the same. still 0? Anyone knows what's happening here?