Bitwise Calculator
Run AND, OR, XOR, NOT, left shift, and right shift operations on two integers. Results are shown in decimal, binary, and hexadecimal so you can see exactly what happens at the bit level.
Bitwise operations work directly on the binary representation of integers, processing each bit position independently. They are essential in low-level programming, networking, graphics, and cryptography.
The Six Operations:
- AND (&): Returns 1 only when both bits are 1. Used for masking specific bits. Example: 12 & 10 = 1100 & 1010 = 1000 = 8.
- OR (|): Returns 1 when at least one bit is 1. Used for setting bits. Example: 12 | 10 = 1100 | 1010 = 1110 = 14.
- XOR (^): Returns 1 when the bits differ. Used for toggling bits and simple encryption. Example: 12 ^ 10 = 1100 ^ 1010 = 0110 = 6.
- NOT (~): Flips every bit. In two's complement, ~n = -(n+1). Example: ~12 = -13.
- Left Shift (<<): Shifts bits left by n positions, filling with zeros. Equivalent to multiplying by 2^n. Example: 3 << 2 = 12.
- Right Shift (>>): Shifts bits right by n positions. Equivalent to integer division by 2^n. Example: 12 >> 2 = 3.
Common Uses:
- Bit masking: Extract or modify specific bits in a value
- Flags: Store multiple boolean values in a single integer
- Permissions: Unix file permissions use bitwise operations
- Fast math: Left shift for multiplication, right shift for division by powers of 2
- Checksums and hashing: XOR is used in many checksum algorithms