티스토리 뷰

Ongoing/Operator

[Operator] Logical & Bitwise

More Code 2018. 6. 24. 20:50

Logical Operator [C# C++ Java] 공통

Operator

Logical

Bitwise

!

NOT

YES

-

&&

AND

YES

-

||

OR

YES

-

!=

XOR

YES

-



Logical Operator [Python]

Operator

Logical

Bitwise

not

NOT

YES

-

and

AND

YES

-

or

OR

YES

-

!=

XOR

YES

-



Bitwise Operator [C# C++ Java Python] 공통

Operator

Logical

Bitwise

~

NOT

-

YES

&

AND

can be used

YES

|

OR

can be used

YES

^

XOR

can be used

YES



아래와 같이 Logical XOR Function(Method)을 정의해서 사용해도 된다.


// [C#] Logical XOR
public static bool XOR(bool x, bool y)
{
return ((x || y) && !(x && y));
}
// or
public static bool XOR(bool x, bool y)
{
return ((x && !y) || (!x && y));
}



// [C++] Logical XOR
bool xor(bool x, bool y) {
  return ((x || y) && !(x && y));
}
// or
bool xor(bool x, bool y) {
  return ((x && !y) || (!x && y));
}



// [Java] Logical XOR
public static boolean xor(boolean x, boolean y) {
return ((x || y) && !(x && y));
}
// or
public static boolean xor(boolean x, boolean y) {
return ((x && !y) || (!x && y));
}



# Python : Logical XOR
def xor(x: bool, y: bool) -> bool:
return (x or y) and not (x and y)
# or
def xor(x: bool, y: bool) -> bool:
return (x and not y) or (not x and y)


'Ongoing > Operator' 카테고리의 다른 글

[C# Python Java] is operator, instanceof operator  (0) 2019.04.20
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함