Posted By

tiaonlab on 04/04/07


Tagged

bitwise odd even


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

shachi


Test if a number is odd or even using bitwise operator


 / Published in: PHP
 

URL: http://www.tiaon.com/wordpress/2007/03/27/the-quicker-way-to/

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.