Bitwise Operations in MQL4
Bitwise operations are performed exclusively on integer types.
Complement to One (~)
b = ~n;char a='a', b; b = ~a; results in a = 97, b = -98.Right Shift (>>)
x to the right by y digits.x = x >> y;char a='a'; b = a >> 1; results in b = 48.Left Shift (<<)
x to the left by y digits.x = x << y;char a='a'; b = a << 1; results in b = -62.Bitwise AND (&)
x and y.x and y are 1.b = ((x & y) != 0); (often used to check if a specific bit is set)char c = a & b; where a='a', b='b' results in c = 96.Bitwise OR (|)
x and y.x or y is 1.b = x | y;char c = a | b; where a='a', b='b' results in c = 99.Bitwise Exclusive OR (^)
x and y.x and y are different.b = x ^ y;char c = a ^ b; where a='a', b='b' results in c = 3.Related Topics
Previous
arrow_back
Boolean operations