Re: math function to change a value 1- 8 to a bit representation
This snippet (not tested) should do the trick.
X VAR byte
Answer VAR byte
X = 128
Gosub Decode
' variable answer should contain your bit position
End
Decode:
Answer = 0
If X < 1 then return
Do while X <> 1
Answer = answer + 1
X = X > 1
Wend
Return
Edited:
Reading again your first post I realise you need the other way around:
X = 8
Gosub Decode
Answer will contain the requested value
End
Decode:
Answer = 0
For i = 1 to X
Answer = answer < 1
Next i
Return
Cheers
Al.
Last edited by aratti; - 20th October 2014 at 10:16.
All progress began with an idea
Bookmarks