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.
Error on MOD operator?
-
- Valued Contributor
- Posts: 548
- Joined: Tue Jun 26, 2007 11:23 am
- Has thanked: 6 times
- Been thanked: 44 times
- Contact:
Re: Error on MOD operator?
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.
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.