View Full Version : better way to do this using math
longpole001
- 4th August 2014, 23:20
hi guys , have mind blank on how to best do this code in math than use a lookup
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
longpole001
- 5th August 2014, 01:11
retry
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
aratti
- 5th August 2014, 01:42
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.
longpole001
- 5th August 2014, 05:21
the manual shows " ^ " to be a bitwise exclusive OR ?
aratti
- 5th August 2014, 06:17
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.
EarlyBird2
- 5th August 2014, 06:59
retry
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.
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.
longpole001
- 5th August 2014, 09:03
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
EarlyBird2
- 6th August 2014, 08:01
Obviously I do not know how this code fits into your main program but here is an idea that could be of use.
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?
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.