Answers for "Determining if a variable is even or odd?"
http://answers.unity.com/questions/224860/determining-if-a-variable-is-even-or-odd.html
The latest answers for the question "Determining if a variable is even or odd?"Answer by firemyst
http://answers.unity.com/answers/618271/view.html
[Here’s a blog article][1] which benchmarks quite a few ways to test if a number is odd or even.
Surprisingly, the fastest way appears to be the modulus % operator, even out performing the bitwise ampersand &, as follows:
for (int x = 0; x < NumberOfNumbers; x++)
{
if (x % 2 == 0)
total += 1; //even number
else
total -= 1; //odd number
}
Definitely [worth a read][2] for those that are curious.
[1]: http://cc.davelozinski.com/c-sharp/fastest-way-to-check-if-a-number-is-odd-or-even "Here's a blog article"
[2]: http://cc.davelozinski.com/c-sharp/fastest-way-to-check-if-a-number-is-odd-or-even "worth a read"Thu, 16 Jan 2014 13:12:38 GMTfiremystAnswer by Tseng
http://answers.unity.com/answers/224863/view.html
Use modulo operator
if(test%2==0) // Is even, because something divided by two without remainder is even, i.e 4/2 = 2, remainder 0
if(test%2==1) // Is odd, because something divided by two with a remainder of 1 is not even, i.e. 5/2 = 2, remainder 1Thu, 08 Mar 2012 02:28:55 GMTTseng