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.

and PutBit()

Function PutBit(value, position, bit = True)
	Return value Or (bit Shl (position - 1))
End Function 


here's a test

a = 128
Print Right$(Bin$(a),8)

Print GetBit(a,7)

a = PutBit(a,4)
Print a
Print Right$(Bin$(a),8)

WaitKey
End 


voila, you can now put up to 8 booleans into one byte.

(there's actually another way to do this, like the way bitflags are done for file attributes, don't feel like getting into it.)