Odd Even Classic

Actionscript:
  1. // from http://www.bit-101.com/blog/?p=729
  2. var number:Number = 10.5;
  3.  
  4. // for numbers
  5. var isEven:Boolean = (number % 2) == 0;
  6. trace(isEven);
  7.  
  8. // for ints
  9. var integer:int = 10;
  10. isEven = (integer & 1) == 0;
  11. trace(isEven);

This is a classic that I've seen all over the place online... found myself needing it today and figured I should post it. It just an easy way to determine if a number is odd or even... I remember originally reading it over at Bit-101.com a few years back...

Two posts today because I think I missed a post recently...

This entry was posted in Math, Operators and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*