I keep running across (someone else’s) code like this
Case
When (variable & (2|4|8|16)>0) Then ...
WHEN (variable & (1|32)>0 Then ...
...
End
I figure what’s happening here is it’s testing whether there is a 1 or a 0 in the 2^1, 2^2, 2^3, or 2^4 places of the variable variable. Is this right? Either way I’m still unclear on why this expression is written in the way it is. I’m unable to find any documentation on this logic mostly because I don’t know what to really call it.
You’re right, the “pipe” symbol
|corresponds to the bitwise OR operator, whereas the ampersand&corresponds to the bitwise AND operator (at least in some databases).They’re checking bits using those bitwise operators. The most likely reason they are doing this the way they did, is for “improved readability”. E.g. it is easier to see which bits are being checked when writing