0
Why is: public class MyClass { public static void main(String[] args ) { int x = 5; x &= 3; System.out.println(x); } } = 1??
Why is the answer equal to one? Please help
3 odpowiedzi
+ 8
& is a bitwise AND operator, so you need to evaluate this expression in binary. (assume size of int type is 1 byte to see it clearly).
int x=5; // 5 --> 0000 0101
// 3 --> 0000 0011
x&=3; // 5&3 --> 0000 0001 --> 1 in decimal system
1 -> true & 0 -> false then 1&1 will result in true and rest all combinations will result in false as an expression will be true only if all conditions in it are true.
+ 1
Thank you Mr. Gaurav
+ 1
Got it now, thanks