Rockwell Automation 1775-S5_SR5,D17756.5.5 User Manual PLC-3 FAMILY I/0 User Manual

Page 102

Advertising
background image

Programming DH and DH+

Message Procedures

Chapter 6

6-11

Shift Operators

The scanner supports the following shift operators:

If you see:

It means the bit shifts:

<<

left

>>

right

The shift operators shift binary values a specified number of bit positions
to the left or right.

When a left arithmetic shift (<<) executes, zeros shift into the rightmost
bits of the expression. The leftmost bits shift out of the expression and are
lost, thus possibly changing the sign bit. The left bit shift operates in this
manner whether operating on 16 or 32 bit values.

PUMP = (PUMP << 1)

PUMP Value:

Bit Pattern (32Ćbits):

Decimal Value:

Before operation

100...00000101

-2147483643

After operation

000...00001010

10

In a similar manner, when a right bit shift (>>) is executed on a 16 bit
value in the data table, zeros shift into the leftmost bits of the expression.
The rightmost bits shift out of the expression and are lost. As shown in
this example, the sign can change when using the shift operators on 16-bit
values.

$N0:1 = ($N0:1 >> 1)

$N0:1 Value:

Bit Pattern (16Ćbits):

Decimal Value:

Before operation

10000011 00000000

-32000

After operation

01000001 10000000

16768

However, the right bit shift works differently when the operation is
performed on 32 bit values such as are created with user symbols, and also
values in the high order integer data table section. In this case, the leftmost
bit of the expression does not change.

If the leftmost bit is a:

Then:

1

a 1 is shifted in from the left.

0

a 0 is shifted in from the left.

Advertising