Test if a number is odd or even using bitwise operator


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. $number & 1;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.