would it be
if value > 2 then VAR.0[VALUE - 1]
cos if value below 2 would be incorrect bit ??
would it be
if value > 2 then VAR.0[VALUE - 1]
cos if value below 2 would be incorrect bit ??
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 09:16.
All progress began with an idea
Hi,
Hmmm....Answer = answer < 1Code: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
If the above is meant to be a shift left operation then what you want is Answer = Answer << 1
However, since Answer is set to 0 at the entry point of the routine shifting it left any number of times will still result in it being 0 when returning.
/Henrik.
I'm a noob myself, but no... The VAR.0[] syntax is a way of addressing each bit and, while it affects the value of the byte, the bits do not interact.
Some examples:
VAR= %00000000 : VAR.0[0] = 1 : 'VAR NOW EQUALS %00000001
VAR= %00000100 : VAR.0[0] = 1 : 'VAR NOW EQUALS %00000101
VAR= %10100001 : VAR.0[1] = 1 : 'VAR NOW EQUALS %10100011
VAR= %11111100 : VAR.0[7] = 0 : 'VAR NOW EQUALS %01111101
As you can see by the last example, turning "off" bits is the same, only assign a 0. Reassigning a bit, already set (or cleared) has no effect.
Just a typo! What else if not shift left.Hmmm....Answer = answer < 1
Cheers
Al.
All progress began with an idea
Bookmarks