We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

tiaonlab on 04/04/07


Tagged

bitwise odd even


Versions (?)


Who likes this?

1 person has 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.