B&B Electronics VFG3000 - Manual User Manual
Page 195

W
RITING
E
XPRESSIONS
C
HOOSING
V
ALUES
R
EVISION
1
P
AGE
179
C
HOOSING
V
ALUES
You may find situations where you want to select between two values—be they integers,
floating-point values or strings—depending on the value of some condition. For example, you
may wish to set a motor’s speed equal to 500 rpm or 2000 rpm based on a flag tag. This
operation can be performed using the
?:
operator, which is unique in that it takes three
arguments, as shown in the example below…
O
PERATOR
P
RIORITY
E
XAMPLE
Selection
Group 13
Fast ? 2000 : 500
This example will evaluate to 2000 if
Fast
is true, and 500 otherwise. The operator can be
thought to be equivalent to the
IF
function found in applications such as Microsoft Excel.
M
ANIPULATING
B
ITS
Fieldbus Gateway Manager also provides operators to perform operations that do not treat
integers as numeric values, but instead as sequences of bits. These operators are known as
bitwise operators.
A
ND
,
O
R AND
XOR
These three bitwise operators each produce a result in which each bit is defined to be equal to
the corresponding bits in the values on the operator’s left-hand and right-hand sides,
combined using a specific truth-table…
O
PERATOR
P
RIORITY
E
XAMPLE
Bitwise AND
Group 8
Data & Mask
Bitwise OR
Group 9
Data | Mask
Bitwise XOR
Group 10
Data ^ Mask
The table below shows the associated truth tables…
A
B
A
&
B
A
|
B
A
^
B
0
0
0
0
0
0
1
0
1
1
1
0
0
1
1
1
1
1
1
0
S
HIFT
O
PERATORS
Fieldbus Gateway Manager also provides operators to shift an integer
n
bits to the left or
right…
O
PERATOR
P
RIORITY
E
XAMPLE
Shift Left
Group 5
Data << 2
Shift Right
Group 5
Data >> 2