Testing a number to see if it's even.
Blitz3D Forums/Blitz3D Beginners Area/Testing a number to see if it's even.
| ||
Is there a better way to return True or False for even-ness than:iseven% = (num% Shr 1)-((num%+1) Shr 1) In a context where num% may be MilliSecs()/1000 (to create flashing text, for instance)? |
| ||
is_odd% = num% And 1 or: is_even% = Not(num% And 1) |
| ||
That would be the logical, rather than mathematical solution. Thanks biggie :D |
| ||
The mathematical solution (which would be slower than the bitwise solution given above) would use the MOD operator.function is_even(num%) if (num MOD 2 = 0) then return true else return false end function |