BitModule
Re: BitModule
Thanks idle for sharing ... very nice and useful
Re: BitModule
Hi Idle
looks like something is wrong with BitArray (probably other structures as well haven't tested), try the below you will see that position 14 (or 15 if we start at 1) is being set not 9!
output
looks like something is wrong with BitArray (probably other structures as well haven't tested), try the below you will see that position 14 (or 15 if we start at 1) is being set not 9!
Code: Select all
Define ar.BitModule::IBitArray
ar = BitModule::New_BitArray(20)
ar\Set(9)
Define *q.ascii, *p = ar\GetBuffer()
Define i,txt.s
For i=0 To MemorySize(*p)
*q = *p + i
txt + RSet( Bin(*q\a), 8, "0") + ">"
Next
Debug txt
Code: Select all
00000000>00000010>00000000> ....
Re: BitModule
You're examining the buffer directly and not in the manner that the BitArray does.said wrote:looks like something is wrong with BitArray (probably other structures as well haven't tested), try the below you will see that position 14 (or 15 if we start at 1) is being set not 9!
If you use the BitArray's interface instead:
Code: Select all
Define ar.BitModule::IBitArray
ar = BitModule::New_BitArray(20)
ar\Set(9)
Define i,txt.s
For i=0 To ar\BitSize()
txt + Str(Bool(ar\get(i) = 1))
If i % 8 = 0 And i > 0
txt + ">"
EndIf
Next
Debug txt
Code: Select all
000000000>10000000>00000000> ....
Re: BitModule
Thanks Demivec for clarifying, now i looked in detail on what's going on and i see that each byte is being processed separately. You are right, yes it is working fine but honestly I was not expecting this ... (should never use blindly anything
)
I was planning to use this to store blocks in files that could be read by other applications, this somehow put restrictions on the usage of this great module

I was planning to use this to store blocks in files that could be read by other applications, this somehow put restrictions on the usage of this great module

Re: BitModule
Hi Said, it's easy enough fix I think
if you change the set and get parts after the "<<" to (7-(index & $07)
I've updated the module with the changes, seems to be ok
if you change the set and get parts after the "<<" to (7-(index & $07)
Code: Select all
*ta\a | (1 << (7-(index & $07)))
Windows 11, Manjaro, Raspberry Pi OS


Re: BitModule
Thanks Idle for updating the module (actually i had already changed it here to suit my needs, exactly as you are suggesting). It is your module and you know all the details, modifications coming from you are the most welcome ones 
Thanks again for sharing this very useful work

Thanks again for sharing this very useful work

Re: BitModule
What is Toggle suposed to do? I thought would invert the bit value, but does nothing.
Code: Select all
EnableExplicit
Define ba.BitModule::IBitArray
ba = BitModule::New_BitArray(4)
ba\Set(2)
Debug ba\Get(2)
ba\Toggle(2)
Debug ba\Get(2)
Re: BitModule
it's a bug left over from reversing the order, replace it with
Code: Select all
Procedure BitArray_Toggle(*this.bitbuffer,index)
Protected *ta.Ascii
If ((index) >> 3) >= *this\inf\size
*this\inf\size = index + 64
*this\inf\BytesUsed = *this\inf\size
*this\buf = ReAllocateMemory(*this\buf,*this\inf\size)
EndIf
If *this\buf
*ta = *this\buf + ((index)>>3)
*ta\a ! (1 << (7-(index & $07)))
EndIf
EndProcedure
Windows 11, Manjaro, Raspberry Pi OS


Re: BitModule
v 1.3.8
Updated to pb 5.42 lts
exported hash functions
removed crc32
added asm popcount x86/x64 and SSE 4.2 for bitcount
added shift left / right (nicked from wilbert)
Updated to pb 5.42 lts
exported hash functions
removed crc32
added asm popcount x86/x64 and SSE 4.2 for bitcount
added shift left / right (nicked from wilbert)
Windows 11, Manjaro, Raspberry Pi OS

