XOR in mql4

 
I really cant find it in reference... Is there XOR?
 
Azael05x:
I really cant find it in reference... Is there XOR?

Yes...see Bitwise Operations.
 

Haha got stumped for a minute or two on this one as well first time needed XOR in MQL.

Just use the not equal Operation: !=

for example if(x != y){...}

x
y
Result
false
false
false
false
true
true
true
false
true
true
true
false


 
Michael Kroeker:

Haha got stumped for a minute or two on this one as well first time needed XOR in MQL.

Just use the not equal Operation: !=

for example if(x != y){...}

The correct answer was given in the post above yours, namely Bitwise Operations! "Not equal to" (!=) is not the same as XOR:

Bitwise Exclusive Operation OR

The 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.

b = x ^ y


Bitwise Operations - Operations and Expressions - Language Basics - MQL4 Reference
Bitwise Operations - Operations and Expressions - Language Basics - MQL4 Reference
  • docs.mql4.com
Bitwise Operations - Operations and Expressions - Language Basics - MQL4 Reference
 
Azael05x:
I really cant find it in reference... Is there XOR?

xor is  if int a,b

xor=(a&&!b)||(!a&&b)

 
jack zorlob: xor=(a&&!b)||(!a&&b)
Do you really expect that people are still watching this thread after four (4) years?
Don't resurrect old threads without a very good reason.
 
del
 
XOR = A != B



 
Dominik Egert #: XOR = A != B

No! It is not. That is true only if A and B are both a single bit.

2021.10.12 19:46:41.232    testscr USDSGD,Daily: 1^3=2.00000000
2021.10.12 19:46:41.232    testscr USDSGD,Daily: 1^2=3.00000000
 

answer #3 seems to be the best - with x & y as conditions & b as overall result (as for XOR)... with such a tip (^) no any violation of XOR logics was noticed by me in real coding in MQL

XOR in mql4
XOR in mql4
  • 2014.06.05
  • www.mql5.com
I really cant find it in reference... Is there XOR...
 
William Roeder #:

No! It is not. That is true only if A and B are both a single bit.

2021.10.12 19:46:41.232    testscr USDSGD,Daily: 1^3=2.00000000
2021.10.12 19:46:41.232    testscr USDSGD,Daily: 1^2=3.00000000

Hi William,

my answer was referring to the bool variables, as seen in the given example. - This is clearly defined by the "NOT"-operator from the (most complex way).

So if this statement is assumed correct, as given by jack zorlob, it must be a boolean interpretation:

xor=(a&&!b)||(!a&&b)

Therefor

XOR = A != B

is right as well, but to speak the same language:

const bool A = false;
const bool B = true;
const bool x_or = (A != B);

No matter the nature of the inputs, though. They could be anything, but need to be interpreted as boolean variable.

Same accounts for the "original" expression, as the "NOT" operator in use is a logical operator.


Therefor I claim this to be correct statement.

Greetings

https://www.mql5.com/en/docs/basis/operations/bool
Documentation on MQL5: Language Basics / Operations and Expressions / Boolean Operations
Documentation on MQL5: Language Basics / Operations and Expressions / Boolean Operations
  • www.mql5.com
Boolean Operations - Operations and Expressions - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: