Category: >> PHP Code >> Easily detect Odd/Even numbers Bookmark and Share

<< lastnext >>

Snippet Name: Easily detect Odd/Even numbers

Description: This is a simple way to tell whether a given number is odd or even. It works via a bitwise compare. You really only need one of these functions, since if a number isn't odd, it's even.

Also see:
» Super Fast Prime Number Finder
» Dates: Oddball Stuff
» Set cookie even after HTML output
» Prevent the 'enter' key from submi...
» Is Number Even?
» Prevent framing a page

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: August 01st, 2009

function odd($var) {
    return($var & 1);
function even($var) {
    return(!($var & 1));
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 7