Posted: Wed Aug 03, 2005 3:32 pm Post subject: Bit array simulation
'These routines allow to manage a bit array .
'For less then 32 bit is more suitable use the bascom "var_name(bit_N°) = 1/0 "
'
'
'
const BitNu0 = 0 ' 1° element Dim B_array(1)
const BitNu7 = 7 ' 7° " Dim B_array(1)
const BitNu8 = 8 ' 8° " Dim B_array(2)
const BitNu127 = 127 ' 127° " Dim B_array(16)
const BitNu128 = 128 ' 128° " Dim B_array(17)
const BitNu255 = 255 ' 255° " Dim B_array(32)
'
'
' bit var.
'
Dim Fl_bit As Bit
'
' byte var.
'
Dim TmpS0 As Byte '
Dim TmpS1 As Byte
Dim TmpS2 As Byte
Dim N_bit As Byte 'n^ bit
'
Dim B_array(32) As Byte 'Max 255 bit
'
'
declare Sub B_set(N_bit As Byte)
declare Sub B_clear(N_bit As Byte)
declare Sub B_test(N_bit As Byte)
'
'..........
'
for N_bit = 0 to 255
call B_set(N_bit)
call B_test(N_bit)
if Fl_bit = 1 then
print "Bit n^ "; N_bit ;" is ON"
else
print "Bit n^ "; N_bit ;" is OFF"
endif
call B_clear(N_bit)
call B_test(N_bit)
if Fl_bit = 1 then
print "Bit n^ "; N_bit ;" is ON"
else
print "Bit n^ "; N_bit ;" is OFF"
endif
next
'
call B_set(BitNu0)
call B_set(BitNu127)
call B_set(BitNu255)
'
End
'
'.........................
'
Sub B_set(N_bit as byte)
call B_locate
TmpS0 = 1
shift TmpS0,left,TmpS2
TmpS2 = B_array(TmpS1)
TmpS2 = TmpS2 or TmpS0
B_array(TmpS1) = TmpS2
End sub
'
'
Sub B_clear(N_bit as byte)
call B_locate
TmpS0 = 254
rotate TmpS0,left,TmpS2
TmpS2 = B_array(TmpS1)
TmpS2 = TmpS2 and TmpS0
B_array(TmpS1) = TmpS2
End sub
'
'
Sub B_test(N_bit as byte)
call B_locate
TmpS0 = 1
shift TmpS0,left,TmpS2
TmpS2 = B_array(TmpS1)
TmpS2 = TmpS2 and TmpS0
Fl_bit = 0
if TmpS2 > 0 then Fl_bit = 1
End sub
'
'
Sub B_locate
TmpS1 = N_bit
shift TmpS1,right,3
incr TmpS1
TmpS2 = N_bit mod 8
End sub
'
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum