bitwise operators. Pretty annoying to use but... whatever.
>> right bitwise shift
1010101 >> 1 =
0101010
<<left bitwise shift
1010101 << 2 =
1010100
also, the and, or, and xor operators are bitwise.
101011 and
111100 =
101000
110000 or
000011 =
110011
110010 xor
011001 =
101011
tempnum as byte
cursorx as integer = 3
cursory as integer = 3
for a=0 to 255
tempnum=a
for b=0 to 7
text cursorx+(7-b)*10,cursory,str$(bit_truefalse(tempnum,b))
next b
inc cursory,16
if cursory>screen height()
cursory=3
cursorx=cursorx+9*10
endif
NEXT
sync
wait key
end
function bit_truefalse(number as byte, bit as integer)
`number could be pretty much any type, but byte is simple. Could be float, dword, integer, whatever.
`"bit" is a number between 0 and sizeof(number)-1 IE...
`number: 01001010
`bit #: 76543210
number=number>>bit
`if bit=4, number goes from 01011010, shifted right, to 00000101
number=number and 1
`00000101 and
`00000001
`is 1 if the bit is 1, or 0 if the bit is 0.
endfunction number
[edit] bit truefalse condenses to:
function bit_truefalse(number as byte, bit as integer)
number=(number>>bit) and 1
endfunction number