Accessing Bits

BlitzMax Forums/BlitzMax Programming/Accessing Bits

To isolate only one bit (or a set of bits) and exclude all the rest, AND a mask with the value. What you have left is only the bits you asked for.

Also if you don't know what bit you're looking for, put $1 into a variable, then use:

Local a:Int=$1 Shl BitNumber

to move that bit into the bit that you want (numbered from 0). Then that gives you the mask with which you can isolate the bit in whatever value you have. Then you can do:

Value=(Value & ($1 Shl BitNumber)) Shr BitNumber

if you want to put that bit right justified in the variable, so you can do math on it