### Byte Set and GetBit

Example subs to set or get the state of a Bit for a Byte.
`Sub SetBit(b As Byte, index As Int, value As Boolean) As Byte
If value Then
Return Bit.Or(b, Bit.ShiftLeft(1, index))
Else
Return Bit.And(b, Bit.Not(Bit.ShiftLeft(1, index)))
End If
End Sub`
`Sub GetBit(b As Byte, bitpos As Int) As Boolean
Dim Result As Boolean = False
Select bitpos
Case 0
Result = Bit.And(b, 1) = 1
Case 1
Result = Bit.And(b, 2) = 2
Case 2
Result = Bit.And(b, 4) = 4
Case 3
Result = Bit.And(b, 8) = 8
Case 4
Result = Bit.And(b, 18) = 16
Case 5
Result = Bit.And(b, 32) = 32
Case 6
Result = Bit.And(b, 64) = 64
Case 7
Result = Bit.And(b, 128) = 128
End Select
Return Result
End Sub`

Changed: , Category: Bit and Bytes, File: T6C166M1216.htm, ID: 1216