MQL4 Reference Language Basics Operations and Expressions Bitwise Operations
Bitwise OperationsComplement to OneComplement of the variable value up to one. The value of the expression contains 1 in all digits where the variable value contains 0, and 0 in all digits where the variable contains 1.
Example:
Right ShiftThe binary representation of x is shifted to the right by y digits. If the value to shift is of the unsigned type, the logical right shift is made, i.e. the freed left-side bits will be filled with zeroes. If the value to shift is of a sign type, the arithmetic right shift is made, i.e. the freed left-side digits will be filled with the value of a sign bit (if the number is positive, the value of the sign bit is 0; if the number is negative, the value of the sign bit is 1).
Example:
Left ShiftThe binary representation of x is shifted to the left by y digits, the freed right-side digits are filled with zeros.
Example:
It is not recommended to shift by the number of bits larger or equal to the length of the variable shifted, because the result of such an operation is undefined. Bitwise AND OperationThe bitwise AND operation of binary-coded x and y representations. The value of the expression contains a 1 (TRUE) in all digits where both x and y contain non-zero, and it contains 0 (FALSE) in all other digits.
Example:
Bitwise OR OperationThe bitwise OR operation of binary representations of x and y. The value of the expression contains 1 in all digits where x or y does not contain 0, and it contains 0 in all other digits.
Example:
Bitwise Exclusive Operation ORThe bitwise exclusive OR (eXclusive OR) operation of binary representations of x and y. The value of the expression contains a 1 in all digits where x and y have different binary values, and it contains 0 in all other digits.
Example:
Bitwise operations are performed with integers only. See also |