check if a number is a multiple of 2 (EVEN)

Feb 10, 2014 at 6:23pm

check if a number is a multiple of 2 (EVEN)

can i make an else if statement that can check if a number is a multiple of 2 in other words (EVEN)

what i was thinking was something like this:-

if $i1 =/ 2 then out1 $i1 else out2 $i1

any help would be great i feel like i’m overlooking a simple solution.

many thanks in advance.

MiRAGE

#280668
Feb 10, 2014 at 6:37pm

use modulo. [ if $i1 % 2 == 1 then odd else even ]

#280671
Feb 10, 2014 at 6:58pm

mod 2 of the absolute value of an integer is 0 if it’s even and 1 if it’s odd.

– Pasted Max Patch, click to expand. –
#280672
Feb 10, 2014 at 10:18pm

[& 1] is 0 if even, 1 if odd

#280678

You must be logged in to reply to this topic.