Bits manipulation

Share your advanced PureBasic knowledge/code with the community.
XCoder
User
User
Posts: 72
Joined: Tue Dec 31, 2013 9:18 pm

Re: Bits manipulation

Post by XCoder »

I have written two macros that will set or clear bits and I am posting them here for others to use.

Macro SetBit(MyDWord,bit) ;Bit values are 1, 2, 4, 8, 16, 32. Bits are referenced as 1,2,3...
EnableASM
mov eax, bit
Or MyDWord, eax
DisableASM
EndMacro

and :

Macro ClearBit(MyDWord,bit)
EnableASM
mov eax, bit
XOr eax, $FF
And MyDWord, eax
DisableASM
EndMacro

Both macros operate directly on the variable MyDWord; however, I don't know whether these macros are more or less efficient than the code posted previously.
Post Reply