Logical and '&'
Positron8 · Revision 4.0.6.5 · PDF page 87
Syntax
Assignment Variable = Variable & Variable
Overview
The And operator returns the bitwise And of two values. Each bit of the values is subject to the following logic: -
0 and 0 = 0 0 and 1 = 0 1 and 0 = 0 1 and 1 = 1
The result returned by & will contain 1s in only those bit positions in which both input values contain 1s.
Operands
Variable can be a constant, variable or expression. Assignment Variable can be any valid variable type.
Example 1
Device = 18F26K40 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
Dim bMyVar1 as Byte
Dim bMyVar2 as Byte
Dim bMyResult as Byte
bMyVar1 = 0b00001111
bMyVar2 = 0b10101101
bMyResult = bMyVar1 & bMyVar2
HRsoutLn Bin bMyResult ' Display the AND binary result: 00001101
Example 2
Device = 18F26K40 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
HRsoutLn Bin (0b00001111 & 0b10101101) ' Display the AND binary result: 00001101
Note.
Bitwise operations are not permissible with floating point constants or variables.
