tobyw_1969
New Member
I have been scratching my head to try and find ways to reduce code size..
I had some code to do this sort of thing,
but I thought it might be possible to just convert the state of the input pins into a single number 1-3, like
it would save some bytes, but the problem is, I can't do this, because brackets are only available on x2 parts and I am trying to fit this into an 18M
so i have been racking my brains for binary maths ideas, and searching through the commands available (setbit, toggle etc) to try and find an answer, but I can't work it out
for those of you who weren't made to stand in the corner every maths lesson for organising compass fights - is there a simple way to create a number from 1-3 based on the individual 0/1 values of 3 variables? I thought it might be possible to use shift, but that's not supported on 18M
I had some code to do this sort of thing,
Code:
if pin1 = 1 then
selection = 1
gosub on_selection
else if pin2 = 1 then
selection = 2
gosub on_selection
else if pin3 = 1 then
selection = 3
gosub on_selection
end if
Code:
selection = pin1 + (pin2*2) + (pin3*3)
if selection > 0 then gosub on_selection
so i have been racking my brains for binary maths ideas, and searching through the commands available (setbit, toggle etc) to try and find an answer, but I can't work it out
for those of you who weren't made to stand in the corner every maths lesson for organising compass fights - is there a simple way to create a number from 1-3 based on the individual 0/1 values of 3 variables? I thought it might be possible to use shift, but that's not supported on 18M
Last edited: