|
Author |
Topic: even or odd (Read 629 times) |
|
pokemon#1
|
even or odd
« on: Jul 4th, 2003, 5:40am » |
|
I need help using proce55ing to detect if an increasing integer is even or odd. Can anyone help?
|
|
|
|
benelek
|
Re: even or odd
« Reply #2 on: Jul 4th, 2003, 3:29pm » |
|
you've already got an answer there, but here's a cute little piece of maths i learnt during my days in highschool: (-1)^num if num is even, 1 will result, and if num is odd, -1 will result. so you can use it as a coefficient where a number needs to be greater than zero if it is even, and smaller than zero if odd.
|
|
|
|
v3ga
|
Re: even or odd
« Reply #3 on: Jul 4th, 2003, 6:04pm » |
|
This one should work too : (n & 0x01) == true if n is odd.
|
« Last Edit: Jul 4th, 2003, 6:07pm by v3ga » |
|
http://v3ga.net
|
|
|
pokemon#1
|
Re: even or odd
« Reply #4 on: Jul 4th, 2003, 9:37pm » |
|
Thanks so much. I will post my applet here soon when it is done. All of your ways work, even though I used scloopy's way because it was the first posted.
|
|
|
|
|