When should I use a bitwise operator?

后端 未结 9 903
暗喜
暗喜 2020-12-02 14:01

I read the following Stack Overflow questions, and I understand the differences between bitwise and logical.

  • Difference between & and && in

9条回答
  •  无人及你
    2020-12-02 14:33

    Bitwise is useful for things in PHP just like anything else.

    How about a value that can have multiple states turned on at the same time?

    Output:

    STATE_FOO's base2 value is 00000001
    STATE_BAR's base2 value is 00000010
    STATE_FEZ's base2 value is 00000100
    STATE_BAZ's base2 value is 00001000
    
    base10 value of $state is 5
    base2 value of $state is 00000101
    Does $state include FOO state? 1
    Does $state include BAR state?
    Does $state include FEZ state? 1
    Does $state include BAZ state?
    Is state equivalent to FOO and FEZ states? 1
    

提交回复
热议问题