Home

Public Domain Photos

Free for commercial redistribution and alteration (All photo from http://publicphoto.org/ is 100% free for use)

Testing odd or even number – php script

numbersTesting odd or even numbers with modulo or php bitwise operators:

1. The fastest function, using php binary AND operator (Bitwise)

<?php
function is_odd( $int ) {
return( $int & 1 );
}
?>

2. and the alternative using php modulo operator (Arithmetic)

<?php
function is_odd($number) {
return $number%2;
}
?>

** NOTE ** script using bitwise operations more efficiently than modulo !!!

[ Short URL ... ]

Leave a Reply

 

Powered by WordPress ::