Break On
$TB = 'C3' ; starting hex value
$TB = Val('&' + Right($TB, 2)) ; convert hex to decimal value
'TB: ' $TB ?
; "toggle" changes the state - on if off, off if on - via XOR (Exclusive OR)
$TB = $TB ^ 1 ; toggle bit 1
'TB: ' $TB ?
$TB = $TB ^ 1 ; toggle bit 1 again
'TB: ' $TB ?
; turn on a specific bit based on bit-positional value using OR
$TB = $TB | 8 ; turn on bit 8
'TB: ' $TB ?
; Turn a specific bit off based on bit-positinoal value using AND
; Allow all bits other than the one to be turned off
$On = 128+64+32+16+4+2+1 ; define allowed bits in byte
$TB = $TB & $On ; turn bit 8 off by allowing all other bits except 8
'TB: ' $TB ?
; Determine if bit 5 is on - bit 5 is 16 decimal
'Bit 5: '
If $TB & 16
'On' ?
Else
'Off' ?
EndIf
; Determine if bit 2 is on - bit 2 is 2 decimal
'Bit 2: '
If $TB & 2
'On' ?
Else
'Off' ?
EndIf