Bitwise Calculator
Output
Understanding Bitwise Operations
Bitwise operations work directly on the binary representations of numbers. They are fundamental in many low-level programming tasks, including system programming, cryptography, and algorithms that require direct hardware manipulation.
Operations:
- AND (`&`): Returns 1 for each bit position where both numbers have 1.
- Example: `5 & 3`
- Binary: `0101 & 0011 = 0001`
- Result: `1`
- OR (`|`): Returns 1 for each bit position where at least one of the numbers has 1.
- Example: `5 | 3`
- Binary: `0101 | 0011 = 0111`
- Result: `7`
- XOR (`^`): Returns 1 for each bit position where the bits of the numbers are different.
- Example: `5 ^ 3`
- Binary: `0101 ^ 0011 = 0110`
- Result: `6`
- NOT (`~`): Inverts all bits of a number. Example shown for two's complement systems.
- Example: `~5`
- Binary: `~0101 = 1010` (two's complement: `-6`)
- Result: `-6`