Code: Alles auswählen
;Nummerierung der Bits "von hinten nach vorne"
;Bit0:Wert 1
;Bit1:Wert 2
;...
;Bit7:Wert 128
EnableExplicit
Procedure ReadOutBit(ByteMemoryID,Bit)
If PeekQ(ByteMemoryID) & Int(Pow(2,Bit))
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure WriteInBit(ByteMemoryID,Bit,Value)
If Value=0
PokeB(ByteMemoryID,PeekB(ByteMemoryID)&~Int(Pow(2,Bit)))
ElseIf Value=1
PokeB(ByteMemoryID,PeekB(ByteMemoryID)|Int(Pow(2,Bit)))
EndIf
EndProcedure
;Beispiel:
Global Byte.b=16
Debug RSet(Bin(Byte),8,"0")
Debug ReadOutBit(@Byte,4) ;Bit4 auslesen: sollte 1 ergeben
Debug ReadOutBit(@Byte,5) ;Bit5 auslesen: sollte 0 ergeben
Debug ""
WriteInBit(@Byte,0,1) ;Bit0 (1er-Bit) auf 1 setzen
Debug RSet(Bin(Byte),8,"0")
Debug Byte ;Byte sollte nun den Wert 17 haben