Posted By

tiaonlab on 04/04/07


bitwise odd even

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Test if a number is odd or even using bitwise operator

 / Published in: PHP


In PHP & or AND is a bitwise operator. When used it performs bitwise operation between two numbers. In the following example, the operator will test if the last bit of $number is 1. Thus successfully tests if $number is even or odd.

  1. $number & 1;

Report this snippet  

You need to login to post a comment.