GetBit
Positron16 · Revision 1.1.3.5 · PDF page 336
Syntax
Assignment Variable = GetBit Variable, Index
Overview
Examine a bit of a variable, or register.
Parameters
Index is a constant, variable, or expression that points to the bit within Variable that requires examining. Assignment Variable is a user defined variable.
Example
' Examine and display each bit of variable MyByte
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 16
Declare Hserial_Baud = 9600 ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
Dim MyByte as Byte
Dim Index as Byte
Dim Var1 as Byte
RPOR7 = 3 ' Make PPS Pin RP14 U1TX
MyByte = %10110111
While ' Create an infinite loop
HrsoutLn Bin8 MyByte ' Display the original variable
For Index = 7 to 0 Step -1 ' Create a loop for 8 bits
Var1 = GetBit MyByte, Index ' Examine each bit of MyByte
Hrsout Dec1 Var1 ' Display the binary result
DelayMs 100 ' Slow things down to see what's happening
Next ' Close the loop
Hrsout 13
Wend ' Do it forever
