Pages

Friday, June 26, 2009

An easy way to check if a number is odd or even

Using the bitwise operator AND you can check if a number is odd or even.

private bool IsOdd(int i)
{
return (i&1==1);
}


If the function IsOdd() returns true then the number is odd otherwise, the number is even.

I posted this entry in my new blog at http://www.elgrillo.eu/blog. The new blog is about programming.

No comments: