better way to do this using math
hi guys , have mind blank on how to best do this code in math than use a lookup
Code:
if val < 6 AND Menu_Select = 211 then lookup val,[0,2,4,8,16,32],val
if val =>6 and val <= 11 and Menu_Select = 2112 then lookup val-6,[0,2,4,8,16,32],val
if val =>12 and Menu_Select = 2113 then lookup val-12,[0,2,4,8,16,32],val
Re: better way to do this using math
retry
Code:
if val < 6 AND Menu_Select = 211 then lookup val,[1,2,4,8,16,32],val
if val =>6 and val <= 11 and Menu_Select = 2112 then lookup val-6,[1,2,4,8,16,32],val
if val =>12 and Menu_Select = 2113 then lookup val-12,[1,2,4,8,16,32],val
Re: better way to do this using math
Power 2 to the value of val ( 2^val) and you will get the same value as your lookup table.
Since 2^0 = 1 you will use an if then to turn it into zero.
Cheers
Al.
Re: better way to do this using math
the manual shows " ^ " to be a bitwise exclusive OR ?
Re: better way to do this using math
Forgotten that PBP has not the power. Well you can use the shift left. Every shift you multiply by two so B1 = B0 << val where B0 = 1. Still need the filter to turn the one into zero, when val = 0.
Cheers
Al.
Re: better way to do this using math
Quote:
Originally Posted by
longpole001
retry
Code:
if val < 6 AND Menu_Select = 211 then lookup val,[1,2,4,8,16,32],val
if val =>6 and val <= 11 and Menu_Select = 2112 then lookup val-6,[1,2,4,8,16,32],val
if val =>12 and Menu_Select = 2113 then lookup val-12,[1,2,4,8,16,32],val
Obviously I do not know how this code fits into your main program but here is an idea that could be of use.
Code:
WHILE val > 5
val = val - 6
wend
val = 1 << val
I am not sure about this line "val = 1 << val " just try it is all I can suggest.
Re: better way to do this using math
yep i did not see an easy math "power " option , which would be good
i am just trying to save code space a bit, lookups take more code space than math calc
Re: better way to do this using math
Quote:
Originally Posted by
EarlyBird2
Obviously I do not know how this code fits into your main program but here is an idea that could be of use.
Code:
WHILE val > 5
val = val - 6
wend
val = 1 << val
I am not sure about this line "val = 1 << val " just try it is all I can suggest.
Sheldon,
I have tested this and it works a treat. It must save a lot of code space compared to your original three lines?