i currently had a glance with bit operators in java such as Summary of Operators (The Java™ Tutorials > Learning the Java Language > Language Basics) bitwise and bit shift operators. given the following code i understand how they work, and some articles telling the usage and difference of logical operators vs usage of bitwise operators(e.g && and & , || and |)
i understand that the single &(bitwise AND), |(bitwise exclusive OR) and ^(bitwise inclusive OR) between 2 integers performs a Binary/Boolean multiplication and addition(given the logic of boolean arithmetic).Code :
System.out.println(3 & 6); // results in an integer 2 System.out.println(3 | 6); // results in an integer 7 System.out.println(3 ^ 6); // results in an integer 5
this one shifts the binary value of 16, 3 times to the left, getting a value 128, vice versa if shifted using >> right shift operator, 16's binary value will be shifted to the right 3 times.Code :
System.out.println(16 << 3); // resutls in an integer 128
The double sign logical operators performs a short circuit operation, but a single sign logical operators(bitwise) always evaluate all the operands(e.g false & true, will be both evaluated). i found out that, although Bitwise operators can be used in a Boolean EXPRESSION/CONDITION, it was not intended for it, my conclusion was, it was intended for a Boolean/Binary arithmetic. is my conclusion right?
My question is, what is Bitmasking? is it a very technical hardcore thing to understand? articles i've read, doesnt give me a very handy answer.. maybe asking here might enlighten me given the knowledge i managed to learn with these operators..