Complement ‘~’
Positron16 · Revision 1.1.3.5 · PDF page 88
The Complement operator inverts the bits of an integer value. Each bit that contains a 1 is changed to 0 and each bit containing 0 is changed to 1. This process is also known as a "bitwise not".
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
Dim MyWord1 as Word
Dim MyWord2 as Word
PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX) ' Make Pin RB14 U1TX
MyWord2 = %1111000011110000
MyWord1 = ~MyWord2 ' Complement MyWord2.
HrsoutLn Bin16 MyWord1 ' Display the result on a serial terminal
Complementing can be carried out with all variable types except Floats. Attempting to complement a floating point variable will produce a syntax error. All bit shifts are unsigned, regardless of the variable type used.
