24.01.2015 Views

PLC Programming

  • No tags were found...

Create successful ePaper yourself

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

Bit-Shift Operators<br />

NOT<br />

Bitwise NOT of a bit operand. The operand should be of the type BOOL, BYTE, WORD or DWORD.<br />

Example in IL:<br />

Var1 :BYTE;<br />

LD 2#1001_0011<br />

NOT<br />

ST Var1 (* Result is 2#0110_1100 *)<br />

Example in ST:<br />

Var1 := NOT 2#1001_0011<br />

Example in FBD:<br />

10.3 Bit-Shift Operators<br />

SHL<br />

Bitwise left-shift of an operand : erg:= SHL (in, n)<br />

in gets shifted to the left by n bits. If n > data type width, for BYTE, WORD and DWORD will be filled<br />

with zeros. But if signed data types are used, like e.g. INT, then an arithmetic shift will be executed in<br />

such cases, that means it will be filled with the value of the topmost bit.<br />

Note:<br />

Note:<br />

Please note, that the amount of bits, which is regarded for the arithmetic operation, is pretended by<br />

the data type of the input variable !. If the input variable is a constant the smallest possible data type<br />

is regarded. The data type of the output variable has no effect at all on the arithmetic operation.<br />

See in the following example in hexadecimal notation that you get different results for erg_byte and<br />

erg_word depending on the data type of the input variable (BYTE or WORD), although the values of<br />

the input variables in_byte and in_word are the same.<br />

Example in ST:<br />

10-6 CoDeSys V2.3

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

Saved successfully!

Ooh no, something went wrong!