시간/숫자
비트 연산
지정된 비트 폭(8/16/32/64비트)의 정수에 대한 AND/OR/XOR/NAND/NOR/XNOR/NOT 및 시프트 연산, 모든 진법에서.
(시프트할 비트 수, 10진수)
Bitwise operations work directly on a number's individual bits rather than its value as a whole — the basis for permission flags, network protocols, and low-level optimization.
How to use it
- Enter one or two numbers in any base (binary, hex, decimal) and pick an operation (AND, OR, XOR, NAND, NOR, XNOR, NOT, or a shift).
- Pick a bit width (8/16/32/64 bits) — it affects how NOT and shifts behave at the number's boundaries.
- The result is shown instantly in several number bases for easy comparison.
Common uses
- Working with permission or setting flags packed into a single number (file system access rights, for example).
- Debugging a network protocol or binary format where fields are packed at the individual-bit level.
- A teaching example for understanding binary number representation and operations on it.
Things to keep in mind
The result of NOT and shifts depends on the chosen bit width — the same number gives a different result at 8-bit versus 32-bit width because of the different number of bits involved.
XOR is often used to toggle a flag — applying XOR twice with the same value returns the original.
자주 묻는 질문
AND, OR, XOR, NAND, NOR, XNOR, NOT의 차이는 무엇인가요?
AND는 두 비트가 모두 1일 때만 1을 반환하고, OR은 적어도 하나가 1일 때 1을 반환하며, XOR은 비트가 다를 때 1을 반환합니다. NAND/NOR/XNOR은 이들의 부정이며, NOT은 단일 피연산자의 모든 비트를 반전시킵니다.
숫자의 비트 폭과 부호는 어떻게 처리되나요?
8/16/32/64비트 폭을 선택하세요 — 연산과 시프트는 해당 범위 내에서 이루어집니다. 음수는 2의 보수로 표현되므로, 10진 표기법에 익숙하다면 NOT이나 시프트의 결과가 예상과 다르게 보일 수 있습니다.
왼쪽 시프트와 오른쪽 시프트의 차이는 무엇인가요?
왼쪽 시프트(<<)는 오른쪽에 0을 추가하여 실질적으로 시프트 양만큼 2의 거듭제곱을 곱합니다. 오른쪽 시프트는 논리적(왼쪽에 0 추가) 또는 산술적(부호 비트 유지)일 수 있으며, 유형은 선택한 모드에 따라 다릅니다.
"if (a & b == c)" 같은 표현식이 예상과 다르게 동작하는 이유는 무엇인가요?
대부분의 언어에서 비교 연산자 ==는 비트 연산자 &보다 우선순위가 높기 때문에, 이 표현식은 "a & (b == c)"로 계산됩니다. 이를 피하려면 비트 연산에는 항상 괄호를 명시적으로 사용하세요.
개별 불리언 변수 대신 비트 플래그를 사용하는 이유는 무엇인가요?
하나의 숫자에 여러 플래그를 담으면 저장과 전송이 더 간결해지고(예: 네트워크 프로토콜이나 파일 형식), AND/OR/XOR로 특정 플래그를 한 번의 빠른 연산으로 확인하거나 변경할 수 있습니다.