22.11.14 Operation Example

Logical Operation Examples

The following shows logical operation examples.

Result: ON

Result: OFF

Result: ON

Result: OFF

Result: OFF

Result: ON

Result: True if D200 is less than 10.

Result: True if D200 is 0.

Result: True if D200 is 2 or 5.

Result: True if D200 is greater than 5 and less than 10.

Result: True if D200 is less than 5, and D300 is less than 8.

Bit Operation Examples

The following shows bit operation examples.

Result: The data in D200 is shifted 4 bits to the left.

Result: The data in D200 is shifted 4 bits to the right.

[w:[PLC1]D00200] = [w:[PLC1]D00300] >> [w:[PLC1]D00301]
Result: The data in D300 is shifted 12 bits to the right and assigned to D200.

Result: The data in D200 is shifted 4 bits to the left.

Result: The data in D200 is shifted 4 bits to the right.

[w:[PLC1]D00200] = [w:[PLC1]D00300] >> [w:[PLC1]D00310]
Result: The data in D300 is shifted 12 bits to the right and assigned to D200.

0 & 0      // Result: 0
0 & 1      // Result: 0
1 & 1      // Result: 1
0x1234 & 0xF0F0 // Result: 0x1030

0 | 0      // Result: 0
0 | 1      // Result: 1
1 | 1      // Result: 1
0x1234 | 0x9999 // Result: 0x9BBD

0 ^ 0      // Result: 0
0 ^ 1      // Result: 1
1 ^ 1      // Result: 0

~ 0 // Result: 0xFFFF
~ 1 // Result: 0xFFFE

Conditional Branch Usage Calculation Examples

Control program flow using "if-endif" and "if-else-endif"

if (condition)
{Process 1}
endif

If the condition is true, Process 1 is run. If false, skips Process 1.

For example,

if ([w:[PLC1]D00200] < 5)
{
 [w:[PLC]D00100] = 1
}
endif

If data in D200 is less than 5, then assigns 1 to D100.

if (condition)
{Process 1}
else
{Process 2}
endif

If the condition is true, runs Process 1. If false, runs Process 2.

For example,

if ([w:[PLC1]D00200] < 5)
{
 [w:[PLC1]D00100] = 1
}
else
{
 [w:[PLC1]D00100] = 0
}
endif

If the value in D200 is less than 5, assigns 1 to D100. Otherwise, assigns 0.

Offset Address Usage Calculation Examples

Offset Specification: Special Calculation Examples Using [w:[PLC1]D00100]#[t:0000].

100+65526=64(Hex)+FFF6(Hex)=1005A*1(Hex)→005A(Hex)=90

100+(-10)=64(Hex)+FFF6(Hex)=1005A*1(Hex)→005A(Hex)=90

100+4294901840=64(Hex)+FFFF0050(Hex)=FFFF00B4*1(Hex)→00B4(Hex)=180

100+(-65456)=64(Hex)+FFFF0050(Hex)=FFFF00B4*1(Hex)→00B4(Hex)=180

*1 Bottom 16 bits are valid