Hi,
here is my final version:
Code: Select all
#MaxBits = 1024
Macro BitArraySize(Bits)
((Bits - 1) / 32 + 1)
EndMacro
Structure Test
arry.l [BitArraySize(#MaxBits)]
EndStructure
Define myTest.Test
Dim NormalArray.l(BitArraySize(#MaxBits))
Debug "Arraysize: " + Str(ArraySize(NormalArray()))
Procedure InitBits(*A.l, Bits.i, Value.l)
If Value <> 0 : Value = $FFFFFFFF : EndIf
FillMemory(*A, BitArraySize(Bits) * 4, Value, #PB_Long) ; * 4 because we need the bytesize
EndProcedure
Procedure SetBit(*A.l, Index.i)
*A + (Index >> 5)
PokeL(*A, PeekL(*A) | (1 << (Index & $1F)))
EndProcedure
Procedure ClrBit(*A.l, Index.i)
*A + (Index >> 5)
PokeL(*A, PeekL(*A) &~ (1 << (Index & $1F)))
EndProcedure
Procedure TglBit(*A.l, Index.i)
*A + (Index >> 5)
PokeL(*A, PeekL(*A) ! (1 << (Index & $1F)))
EndProcedure
Procedure.i GetBit(*A.l, Index.l)
*A + (Index >> 5)
ProcedureReturn (PeekL(*A) & (1 << (Index & $1F))) >> (Index & $1F)
EndProcedure
InitBits(@myTest\arry, #MaxBits, #True)
SetBit(@myTest\arry, 4)
Debug GetBit(@myTest\arry, 4)
ClrBit(@myTest\arry, 4)
Debug GetBit(@myTest\arry, 4)
TglBit(@myTest\arry, 4)
Debug GetBit(@myTest\arry, 4)
InitBits(@NormalArray(), #MaxBits, #False)
SetBit(@NormalArray(), 144)
Debug GetBit(@NormalArray(), 144)
ClrBit(@NormalArray(), 144)
Debug GetBit(@NormalArray(), 144)
TglBit(@NormalArray(), 144)
Debug GetBit(@NormalArray(), 144)
Now it uses long for the speed.
And I had a fault with the parameter of the NormalArray:
The address of the first element is
@NormalArray() and not @NormalArray
Bernd