@mark
I don't know why anonymous1337 is trying to show you how to
set bits.. Lol?
phishguy's method is correct, but from your OP it appears that you want bit #4 ("the 5th bit" from the right), where bits are numbered right to left from zero. So bit(a,4).
Code: Select all
'
' 7 6 5 4 3 2 1 0 ' bit "place" number
' 0 1 1 1 0 0 1 0 ' 114, binary
^ ' the "5th bit", bit #4
' 128 64 32 16 8 4 2 1 ' decimal value of each bit-place
'
'
'bit(a,4)
Note that the decimal value of bit #4 is 16. If you use the binary operator "and", as in:
Code: Select all
'
print 114 and 16
'
' 0 1 1 1 0 0 1 0 ' 114, binary
' 0 0 0 1 0 0 0 0 ' 16, binary
'
the return value will be 16 if bit #4 is set in 114, 0 otherwise.
Your code with all 3 methods:
Code: Select all
'file: bit_value
'DOES: detect value of 5th bit in data byte
dim as integer a '114
dim as string b 'binary of a = 01110010
'note: if the 5th bit in b (bits run 0 to 7) is set to 1, int returned
a = 114
b= bin(a)
'
if mid( right (b,5),1,1)= "1" then
print "interrupt returned"
else
print "no interrupt"
end if
'
if (bit(a,4)) then ' bit(a,4) = -1
print "interrupt returned"
else
print "no interrupt"
end if
'
if (a and 16) then ' a and 16 > 0
print "interrupt returned"
else
print "no interrupt"
end if
'
sleep:end
I'm not always the best choice to explain things..