Nice work, as always

Code: Select all
Procedure PokeBit(base,bitno,bit)
modulo=bitno%8
base+(bitno-modulo)>>3
If bit
PokeB(base,PeekB(base)|(1<<modulo))
Else
PokeB(base,PeekB(base)&(~(1<<modulo)))
EndIf
EndProcedure
Procedure PeekBit(base,bitno)
modulo=bitno%8
ProcedureReturn (PeekB(base+(bitno-modulo)>>3)>>modulo)&1
EndProcedure
Procedure PokeBits(base,bitno,width,value)
For loop=0 To width-1
PokeBit(base,bitno,value&1)
bitno+1
value>>1
Next
EndProcedure
Procedure PeekBits(base,bitno,width)
result=0
For loop=0 To width-1
result|(PeekBit(base,bitno)<<loop)
bitno+1
Next
ProcedureReturn result
EndProcedure
Code: Select all
Procedure PeekBit(base,bitno)
modulo=bitno%8
ProcedureReturn (PeekB(base+(bitno-modulo)>>3)>>modulo)&1
EndProcedure
variable = 1240 ; which is %11011000 in binary
result$ = ""
For i = 0 To 31
result$ = Str( PeekBit( @variable, i ) ) + result$
Next
Debug result$
Debug RSet( Bin( variable ), 32, "0" )
Code: Select all
;/ Author : DoubleDutch
;/ Set bit n° 'bitno' with 'bit'
Procedure PokeBit(base,bitno,bit)
modulo=bitno%8
base+(bitno-modulo)>>3
If bit
PokeB(base,PeekB(base)|(1<<modulo))
Else
PokeB(base,PeekB(base)&(~(1<<modulo)))
EndIf
EndProcedure
;/ Return bit n° 'bit' of the value stored @base
Procedure PeekBit(base,bitno)
modulo=bitno%8
ProcedureReturn (PeekB(base+(bitno-modulo)>>3)>>modulo)&1
EndProcedure
;/ Fill bits @base, starting @bitno, width specify the nb of byte, value specify the value ( ex : %1111)
Procedure PokeBits(base,bitno,width,value)
For loop=0 To width-1
PokeBit(base,bitno,value&1)
bitno+1
value>>1
Next
EndProcedure
;/ Return bits, @base, width define the number of bits to return, bitno specify which bit is the first
Procedure PeekBits(base,bitno,width)
result=0
For loop=0 To width-1
result|(PeekBit(base,bitno)<<loop)
bitno+1
Next
ProcedureReturn result
EndProcedure
;/ Test
value=%00000000000000000000000000000000
PokeBit(@value,31,1)
Debug Bin(value)
Debug PeekBit(@value,31)
PokeBits(@value,0,5,%11111)
Debug Bin(value)
Debug Bin(PeekBits(@value,0,3))
Code: Select all
Procedure PokeBit(base,bitno,bit)
modulo=bitno%8
base+(bitno-modulo)>>3
If bit
PokeB(base,PeekB(base)|(1<<modulo))
Else
PokeB(base,PeekB(base)&(~(1<<modulo)))
EndIf
EndProcedure
value=0
For i=0 To 31
PokeBit(@value,i,1)
Debug RSet(Hex(value),8,"0") + ", " + Str(value)
PokeBit(@value,i,0)
Next
Code: Select all
PokeBit(5000,9,1)
Code: Select all
PokeBits(5000,9,3,8)
Code: Select all
hi_nibble=PeekBits(memory,4,4) ; read bits 4,5,6,7 as a number 0-15
lo_nibble=PeekBits(memory,0,4) ; read bits 0,1,2,3 as a number 0-15
Code: Select all
r=PeekBits(memory,11,5) ; read red as a number 0-31
g=Peekbits(memory,5,6) ; read green as a number 0-63
b=PeekBits(memory,0,5) ; read blue as a number 0-31
Code: Select all
PokeBits(memory,11,5,r)
PokeBits(memory,5,6,g)
Pokebits(memory,0,5,b)
Gif and Swf (flash) binary files headers are stored in this way, so I'll upgrade to those nice routines when neededDoubleDutch wrote:They are routines to help change/read memory bits easily. If you have some packed data that isn't a byte, word or londword its usually quite a messy thing to do easily.
Got an error at installation,Library Name: DROOPY LIB
Library Version: 1.27
Library Author: DROOPY
PureBasic Version: 3.93
OS Version: WINDOWS