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.

Well, yeah I realized the put bit didn't work to clear a bit...

How bout this:

Function GetBit(value,position)
	Return (value Shr (position - 1)) And 1
End Function 

Function SetBit(value, position)
	Return value Or (1 Shl (position - 1))
End Function 

Function UnSetBit(value, position)
	Return value And ~(1 Shl (position - 1)) 
End Function 

Function ToggleBit(value,position)
	Return (1 Shl (position - 1)) Xor value
End Function 


He doesn't have to understand the bitwise math to use them as black box functions ;)