25.07.2014 Views

1756-PM003H-EN-E, SFC and ST Programming Languages ...

1756-PM003H-EN-E, SFC and ST Programming Languages ...

1756-PM003H-EN-E, SFC and ST Programming Languages ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6-10 Program Structured Text<br />

Use bitwise operators<br />

Bitwise operators manipulate the bits within a value based on two values.<br />

For: Use this operator: Optimal Data Type:<br />

bitwise AND &, AND DINT<br />

bitwise OR OR DINT<br />

bitwise exclusive OR XOR DINT<br />

bitwise complement NOT DINT<br />

For example:<br />

Use this format:<br />

value1 operator value2<br />

Example:<br />

For this situation:<br />

If input1, input2, <strong>and</strong> result1 are DINT tags <strong>and</strong> your<br />

specification says: “Calculate the bitwise result of<br />

input1 <strong>and</strong> input2. Store the result in result1.”<br />

You’d write:<br />

result1 := input1 AND<br />

input2;<br />

Determine the order of execution<br />

The operations you write into an expression are performed in a prescribed<br />

order, not necessarily from left to right.<br />

• Operations of equal order are performed from left to right.<br />

• If an expression contains multiple operators or functions, group the<br />

conditions in parenthesis “( )”. This ensures the correct order of<br />

execution <strong>and</strong> makes it easier to read the expression.<br />

Order:<br />

Operation:<br />

1. ( )<br />

2. function (…)<br />

3. **<br />

4. − (negate)<br />

5. NOT<br />

6. *, /, MOD<br />

7. +, - (subtract)<br />

8. =<br />

9. =, <br />

10. &, AND<br />

11. XOR<br />

12. OR<br />

Publication <strong>1756</strong>-<strong>PM003H</strong>-<strong>EN</strong>-E (excerpt from <strong>1756</strong>-PM001H-<strong>EN</strong>-P) - August 2005

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!