Python의 binary bitwise operoator는 다음과 같음.
표에서 binary result부분은 다음과 같은 x, y 에서의 결과임.
- x : 0b0101 ( = 5 )
- y : 0b0001 ( = 1)
| Operator | Description | Example | Decimal result | Binary result |
| & | And | x & y | 1 | 0b0001 |
| | | Or | x | y | 5 | 0b0101 |
| ^ | Exclusive Or | x ^ y | 4 | 0b0100 |
| ~ | Flip bits | ~x | -6 | binary representation depends on int size |
| << | Left shift | x << 1 | 10 | 0b1010 |
| >> | Right shift | x >> 1 | 2 | 0b0010 |
Note : Flip bits (not 연산)

https://dsaint31.me/mkdocs_site/CE/ch01/negative_number/#2s-complement
BME228
Negative Number 컴퓨터에서 bit로 음수를 표현하는 방법은 크게 다음의 3가지가 있음. Sign and Magnitude 1's Complement (1의 보수) 2's Complement (2의 보수) ** 가장 널리 사용되는 방식은 2's Complement 이며, 앞의
dsaint31.me
더 읽어보면 URLs
2025.03.26 - [Python] - [Py] Bitwise Operator
[Py] Bitwise Operator
Operand로 int 와 bool , 또는 byte와 bytesarrays의 각 요소만 사용할 수 있다.bytes 나 bytearrays는 직접 사용이 안되고 각 요소 단위로 꺼내서 처리해야 한다.참고로,Bitwise Operator는 Tensor 등에서 Element-wise로
ds31x.tistory.com
https://dsaint31.me/mkdocs_site/CE/ch01/ch01_13_boolean_algebra/#basis-operations
BME228
Boolean Algebra George Boole(1815-1864, 영국)이 고안한 logic을 다루는 algebra로 "True, False를 수학적인 영역으로 포함"시켜 참과 거짓을 1,0에 대입하고, AND, OR, NOT 등의 logical operation을 사용하여 논리적 동작(
dsaint31.me
'Python' 카테고리의 다른 글
| [Python] Unicode and Python: encode and decode (0) | 2024.01.16 |
|---|---|
| [Python] Unicode and Python : Unicode Literal (5) | 2024.01.16 |
| [Python] `struct` 사용하기: bytes 로 C언어 구조체 다루기. (2) | 2024.01.15 |
| [Python] bytes and bytearray: Binary Data for Python (0) | 2024.01.15 |
| [python] Text mode vs. Binary mode: File open (0) | 2024.01.15 |