User manual

218
mikoBasic PRO for PIC32
MikroElektronika
Bitwise Operators
Use bitwise operators to modify individual bits of numerical operands.
Bitwise operators associate from left to right. The only exception is the bitwise complement operator not which associates
from right to left.
Bitwise Operators Overview
Operator Operation
and
bitwise AND; compares pairs of bits and returns 1 if both bits are 1,
otherwise it returns 0
or
bitwise (inclusive) OR; compares pairs of bits and generates a 1 result if
either or both bits are 1, otherwise it returns 0
xor
bitwise exclusive OR (XOR); compares pairs of bits and generates a 1
result if the bits are complementary, otherwise it returns 0
not
bitwise complement (unary); inverts each bit
<<
bitwise shift left; moves the bits to the left, discards the far left bit and
assigns 0 to the right most bit
>>
bitwise shift right; moves the bits to the right, discards the far right bit and
if unsigned assigns 0 to the left most bit, otherwise sign extends
Logical Operations on Bit Level
and 0 1
0 0 0
1 0 1
not 0 1
1 0
or 0 1
0 0 1
1 1 1
xor 0 1
0 0 1
1 1 0
The bitwise operators and, or, and xor perform logical operations on the appropriate pairs of bits of their operands.
The operator not complements each bit of its operand. For example:
$1234 and $5678 ‘ equals $1230
‘ because ..
‘ $1234 : 0001 0010 0011 0100
‘ $5678 : 0101 0110 0111 1000
‘ ----------------------------
‘ and : 0001 0010 0011 0000
‘ .. that is, $1230
‘ Similarly:
$1234 or $5678 ‘ equals $567C
$1234 xor $5678 ‘ equals $444C
not $1234 ‘ equals $EDCB