Writing bits

Blitz3D Forums/Blitz3D Programming/Writing bits

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

While these GetBit and PutBIt Functions are well done, I have to say he probably will understand nothing of it, esp. cause of SHR.

I suggest to read some quick tutorials about BOOLEAN algebra.

When you know each bit has a binary value (1,2,4,8,16,32 etc.) you can test a bit this way (eg. for the bit number 4, that represents a value of 8):

my_byte=rand(0,255)

is_set=(my_byte AND 8)
if is_set=8 then print "Bit 4 is set"

Now to set a bit you will use the OR command

my_byte=my_byte OR 8


and finally to clear a bit you'll use AND NOT()

my_byte=my_byte AND ~(8)

(BTW Snarkbait PutBit lacks of this...if bit=0 then unset etc)

So these are the underlying basics of something rather sophisticated like "Return (value Shr (position - 1)) And 1"

EDIT: the Boolen command NOT doesn't seem to work as desired, instead use the operator "~" that does the same job.