Operation & Software Manual
228
Direct Drives & Systems
Chapter D: Programming ETEL Doc. - Operation & Software Manual # DSC2P 903 / Ver. F / 3/6/05
Application example of the logical operation and. Given X1.1=28=11100:
X1.1&=22 ;After executing this command. X1 variable contains the value 20 (10100) because
there is:
Description of the operation &~:
The operation | (or) sets to 1 one or several bits of a number according to a mask without changing the value
of the bits which are not in the mask. The operation &~ (’not’ ’and’) has been defined in order to set this or these
bits to 0, always without changing the value of the other bits.
Example:
Given X1.1=43=101011 and a mask X2.1=18=010010 which selects the bits 1 and 4 of A (the position of the
1 shows the masked bits). In the following table the grey blanks show that the bits of unmasked A have not
been changed and that the masked bits (bits 4 and 1) are forced either to 1 or to 0.
Operations >> and <<:
The operation >> shifts all bits a number to the right, and the shift is done over 32 bits. If the bit of higher weight
(bit 31) is equal to 1 then 1 is entered, if not it will be 0. The operation << does the inverted operation, it shifts
all bits a number to the left and 0 is always entered. These operations allow the multiplication and division by
2
nd
powers.
Examples:
In the examples, the result is the value which is memorized in X1.1 after executing the command. The start
value of X1.1 is 23=10111 in both cases.
X1.1>>=2 result: 101=5. Shift 2 to the right.
X1.1<<=3 result: 10111000=184. Shift 3 to the left.
Values expressed in binary
Commands Result Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
X1.1=43 43
1 0 1 0 1 1
X2.1=18 (mask) 18 0 1 001 0
X1.1 I =X2.1 59
1 1 1 0 1 1
X1.1 &~ =X2.1 41
1 0 1 0 0 1
28 11100=
And
22 10110=
20 10100=
----------------------------