코딩테스트/코드업
[코드업][기초 100제][파이썬] 비트단위 논리연산와 3항 연산자
내만
2022. 7. 12. 20:05
728x90
반응형

🙆♂️비트단위 논리연산
비트단위 논리연산자가 있습니다.
not은 ~로
and는 &로
or는 | 로
xor은 ^로
시프트는 <<(왼쪽 시프트)와 >>(오른쪽 시프트)가 있습니다.
시프트에 관한 내용은 이 게시물에 정리했습니다.
🚀not

a=int(input())
print(~a) #~a = -a-1, -a = ~a+1
#a=2일 때 -3 출력
이처럼 표현됩니다.
🚀and

a,b=map(int,input().split())
print(a&b)
🚀or

a,b=map(int,input().split())
print(a|b)
🚀xor

a,b=map(int,input().split())
print(a^b)
🚀3항 연산자

a=1;b=2
print(a if(a>b) else b) #b값인 2가 출력됨728x90
반응형