Page 1 of 1
UnrealScript XOR XAND
Posted: Fri Oct 19, 2018 12:42 am
by 'Zac
Hello, in some vanilla UT code, I see return statements that look like this:
or
I understand the usage in an if statement, meaning that
is true if only one is false and one is true (Is this still correct UScript? I never use these one liners )
So my Question is, does....
Code: Select all
....
return Foo & Bar
// returns true if both are true? false if not?
or
Code: Select all
....
return Foo | Bar
// return true if one is false and one is true?
// or return the true value?
It's just always stuck with me since seeing this syntax, and I never see it anywhere else. Discuss below
Re: UnrealScript XOR XAND
Posted: Fri Oct 19, 2018 2:23 am
by Barbie
A single "&" respective "|" means a bitwise AND respective OR, the double ones mean logical AND and OR.
Example:
Code: Select all
var byte a, b;
a = 3; // in dual notation 0000.0011
b = 5; // in dual notation 0000.0101
return a & b; // will return 0000.0001
See also
If used in double variant (logical), just imagine some braces around the expression:
Code: Select all
var bool a, b;
a = true;
b = false;
return a && b; //same as return (a && b) same as return FALSE;
'Zac wrote:I understand the usage in an if statement, meaning that
is true if only one is false and one is true
Hmm, if you have meant
then the expression is TRUE if one of the members is TRUE.
Re: UnrealScript XOR XAND
Posted: Sat Oct 20, 2018 2:55 am
by 'Zac
Thanks for the clearing up! and the links!
Re: UnrealScript XOR XAND
Posted: Sat Oct 20, 2018 3:14 am
by Higor
In UnrealScript | and & are used as bitwise operators for integer types, and both RHS and LHS (right hand side, left hand side) are tested.
When it comes to || and &&, these are boolean operators with a 'skip' qualifier, LHS is checked first and depending on the result RHS may or may not be checked.
In other low level languages | and & may be used for many other types, and & may not yield the same results as &&, just as using & may crash your program.
==
Btw, in the case of booleans Exclusive-OR can be evaluated using !=