Bitwise Operations Guide
Bitwise operations act directly on binary digits and are useful for performance-sensitive logic, permissions, protocol parsing, and low-level data handling.
Common Bitwise Operations
| Operation | Rule | Typical Use |
|---|---|---|
AND (&) |
Returns 1 only when both bits are 1. | Mask extraction, bit checks |
OR `( |
)` | Returns 1 when either bit is 1. |
XOR (^) |
Returns 1 when bits are different. | Bit toggle, parity-like checks, state switching |
NOT (~) |
Flips every bit (JavaScript uses signed 32-bit integers). | Fast inversion |
Left Shift (<<) |
Shifts left and fills the right side with 0. | Multiply by powers of 2 |
Right Shift (>>) |
Shifts right and fills the left side with sign bit. | Divide by powers of 2 with sign |
Unsigned Right Shift (>>>) |
Shifts right and always fills the left side with 0. | Unsigned integer handling |
| Base Conversion | Supports decimal/hex/binary/octal I/O. | Debugging and cross-base comparison |
Operation Examples
| Expression | Description | Sample Result |
|---|---|---|
0b1100 & 0b1010 |
AND operation | 0b1000 (8) |
0b1100 | 0b1010 |
OR operation | 0b1110 (14) |
0b1100 ^ 0b1010 |
XOR operation | 0b0110 (6) |
~0b1100 |
NOT operation | ...11110011 (-13) |
0b1100 << 2 |
Left shift by 2 | 0b110000 (48) |
0b1100 >> 2 |
Right shift by 2 | 0b11 (3) |
-8 >>> 2 |
Unsigned right shift by 2 | 1073741822 |
Typical Scenarios
- Color Processing: Extract RGB channels and combine color values.
- Permission Control: Represent, combine, and verify permissions with bitmasks.
- Performance Tuning: Replace some multiply/divide operations with bit operations when appropriate.
- Flag Management: Set, clear, and toggle flags efficiently.
FAQ
Are the results accurate?
This tool follows common calculation rules. For formal or business scenarios, please verify with your actual rules.
Will my input be uploaded?
No. Processing is performed locally in your browser by default.