KaneHarry729
KaneHarry729

Reputation: 95

In Solidity, what does | mean in the context of "if"?

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

Answers (2)

rob74
rob74

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

Geno Chen
Geno Chen

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

Related Questions