Bitwise operators, Bitwise operators – 8 – Rockwell Automation FactoryTalk View Site Edition Users Guide User Manual
Page 554
F
ACTORY
T
ALK
V
IEW
S
ITE
E
DITION
U
SER
’
S
G
UIDE
20–8
• •
•
•
•
Bitwise operators
Bitwise operators examine and manipulate individual bits within a value.
The following table describes the bitwise operators.
OR, ||
or
If either or both statements are true,
returns a 1.
(tag1>tag2) OR (tag1==5)
tag1==5 is true; returns a 1.
NOT
negation
Reverses the logical value of the statement
it operates on.
NOT (tag1
The parentheses are essential in the these expressions. For more information, see “Evaluation
order of operators” on page 20-9.
Bitwise operators are for integers only, not for floating-point numbers.
Symbol
Operator
Action
&
AND
Compares two integers or integer tags on a bit-by-bit basis.
If both the corresponding bits in the original numbers are 1, it returns an
integer with a bit set to 1. Otherwise, the resulting bit is 0.
|
inclusive OR
Compares two integers or tags on a bit-by-bit basis.
If either or both of the corresponding bits in the original numbers are 1, it
returns an integer with a bit set to 1. If both bits are 0, the resulting bit is 0.
^
exclusive OR (XOR)
Compares two integers or tags on a bit-by-bit basis.
If the corresponding bits in the original numbers differ, it eturns an integer
with a bit set to 1. If both bits are 1 or both are 0, the resulting bit is 0.
>>
right shift
Shifts the bits within an integer or tag to the right.
Shifts the bits within the left operand by the amount specified in the right
operand. The bit on the right disappears.
Either a 0 or a 1 is shifted in on the left, depending on whether the left-most
bit is a 0 or a 1. If the left-most bit is 0, a 0 is shifted in. If the left-most bit
is 1, a 1 is shifted in. In other words, the sign of the number is preserved.
<<
left shift
Shifts the bits within an integer or tag to the left.
Shifts the bits within the left operand by the amount specified in the right
operand. The bit on the left disappears and 0 always shifts in on the right.
~
complement
Returns one’s complement; that is, toggles the bits within an integer or tag.
Reverses every bit within the number so every 1 bit becomes a 0 and vice
versa.
Symbols
Operator
Action
Example