Return to Snippet

Revision: 2721
at April 4, 2007 09:25 by tiaonlab


Initial Code
$number & 1;

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

Initial Description
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.

Initial Title
Test if a number is odd or even using bitwise operator

Initial Tags


Initial Language
PHP