John Chris
Senior Member
Hi,
Is there a way to use bitwise logical functions such as OR, AND, etc or other PICAXE supported functions to implement a roll-over for a given set of numbers without using an IF statement. For instance the set of integers 1-12 describes the months in a year. Can we devise a simple combination of functions to take as an input ,the present month, and provide as an output, the month before? e.g. 1 --> 12, and for all other elements in the set n --> n-1. The catch is that conditional statements are not allowed. I am looking for an alternative to the code shown below.
IF input = 1 THEN
output = 12
ELSE
output = input - 1
ENDIF
Thanks,
Chris
________
VAPORIZER
Is there a way to use bitwise logical functions such as OR, AND, etc or other PICAXE supported functions to implement a roll-over for a given set of numbers without using an IF statement. For instance the set of integers 1-12 describes the months in a year. Can we devise a simple combination of functions to take as an input ,the present month, and provide as an output, the month before? e.g. 1 --> 12, and for all other elements in the set n --> n-1. The catch is that conditional statements are not allowed. I am looking for an alternative to the code shown below.
IF input = 1 THEN
output = 12
ELSE
output = input - 1
ENDIF
Thanks,
Chris
________
VAPORIZER
Last edited: