I\'m currently reading an article , but I do not really understand how this work with the logical operator. Can anyone explain this to me?
eg. If I want to have 4 le
This example uses the bitwise shift operator: "<<". This operator takes the bits and shifts them. For example, "1 << 3" results in the number 8. So, in binary,
customer = 0001
employee = 0010
supervisor = 0100
admin = 1000 (I think this was supposed to read 1 << 3)
Now, you can assign people multiple roles using the bitwise-or operator. This would be a single vertical-bar "|". The bitwise or combines the two numbers bit-by-bit, setting each bit that is set in either of the two operands.
myRole = customer | employee = 0011
The if-statement you have is intended to tell whether someone has a particular role. It uses bitwise-and: "&". Bitwise-and combines the two numbers, setting a bit only if the bit is set in both the operands.