Use the left shift operator, Use the left shift operator -9 – Rockwell Automation FactoryTalk View Machine Edition Users Guide User Manual

Page 487

Advertising
background image

23

Use expressions

23-9

• •

Use the left shift operator

If the left bit is a 1 an overflow occurs, and an error message is generated. To prevent this,
use the bitwise AND operator with the left shift operator in an expression. For example:

(dev << 1) & 65535

where dev is a tag whose value is being shifted left, and 65535 is 1111 1111 1111 1111 in
binary form.

|

inclusive OR

Compares two integers or tags on a bit-by-bit basis.

Returns an integer with a bit set to 1 if either or both of the
corresponding bits in the original numbers are 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.

Returns an integer with a bit set to 1 if the corresponding bits
in the original numbers differ. 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, and whether the
operand consists of a signed or unsigned data type.

For signed data types, 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.

For unsigned data types, a 0 is always shifted in.

<<

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.

See “Use the left shift operator,” later in this chapter.

~

complement

Returns one’s complement; that is, it toggles the bits within
an integer or tag.

Reverses every bit within the number so every 1 bit becomes
a 0 and vice versa.

Symbol

Operator

Action (for examples, see page 23-10)

Advertising