search

Home  >  Q&A  >  body text

Why is the result of & operation false?

$x = true;

$y=2;

if($x & $y) is false

if($x & 3) is true

凉伴伴凉伴伴2132 days ago1185

reply all(1)I'll reply

  • 凉伴伴

    凉伴伴2019-05-24 15:23:34

    Answer by yourself, you will understand after reading the next section [Bit Operations]. & and | are both digital operations. They will be operated in binary first and then judged.

    $x and $y++ are converted to binary to 0, so The final result of $x & $y++ is 0, if(0)----false

    3 converted to binary is 11, $x & 3 binary result is 011, converted to decimal is 3, if( 3)----True

    reply
    0
  • Cancelreply