Page 1 of 1

Error on MOD operator?

Posted: Sun Nov 30, 2008 12:29 am
by lulu78
Hello,
That seems too crazy ... I must make a silly mistake! But ...

li is a byte

li = 255 MOD 4 show in variables window 3 ... that's OK

li=0
li = (li-1) MOD 4 show 255 ???

li = (li-1) AND 0b00000011 do the job fine of course.

Some ideas?
Best regards.

Re: Error on MOD operator?

Posted: Sun Nov 30, 2008 12:26 pm
by Sean
Hello,

The problem seems to be caused when the MOD operator is on the same line as the li - 1 calculation.

Performing the 0 - 1 calculation on an unsigned char variable, which requires special treatment, does not seem to simulate correctly when compounded with the MOD operator - possibly due to the variable types used within the Flowcode simulator.
The code should work correctly when downloaded to a target device.

Placing the MOD operator on a separate line (within the same Flowcode block) seems to solve the simulation problem:

li = li - 1
li = li MOD 4

The same problem does not exist with the int variables because they are signed.