"Hi, Amigo!"
"One more little lesson about bitwise operators."
"You know that in addition to the logical operators AND (&&), OR (||) and NOT (!), there are also bitwise operators AND (&), OR (|), NOT (~), and XOR(^), right?"
"Yep. Bilaabo once gave a very good lesson about this."
"Well, about these operators. I've got two things to tell you:"
"First, except for NOT (~), they can be applied to boolean variables, just like logical operators."
"Second, lazy evaluation does not apply to them."
"Look at this example:"
Code | Equivalent code |
---|---|
|
|
"Is the left side more compact than the right?"
"Yep."
"And does it have the same meaning?"
"Yep."
"Quite right. But now look at the same expression using bitwise operators:"
Code | Equivalent code |
---|---|
|
|
"In other words, the code is the same, but absolutely every operation will be performed."
"Note that if a is null, an exception will be thrown when calculating c2!"
"Ah. I can see that more clearly now."
GO TO FULL VERSION