Reputation: 95
I see an if statement in Solidity that looks like this:
// Set a flag if this is an NFI.
if (_isNF)
_type = _type | TYPE_NF_BIT;
What does the |
mean? Usually it means "or", but it doesn't make sense to me here...
Upvotes: 0
Views: 56
Reputation: 5238
It's a bitwise or. As the comment says, the statement sets a flag. E.g. if _type
is (binary) 00100100
and TYPE_NF_BIT
is 00000010
, the result will be 00100110
- i.e. it makes sure that the value of the second bit of _type
is set to 1. This way you can store up to 8 boolean values in a byte.
Upvotes: 1
Reputation: 5214
Bitwise or, a kind of bitwise operation. It can be used for example some on-off flags (indicator) for further operation.
Upvotes: 1