Bitwise Calculator
Perform AND, OR, XOR, NOT and Bit Shifts on 8, 16, 32, and 64-bit integers. Visualize binary bits and convert between Hex, Decimal, and Octal.
About
Low-level programming requires direct manipulation of memory bits. This functionality is essential when developing device drivers, network protocols, or optimizing embedded systems. A single bit error in a status register or a subnet mask causes system instability or security vulnerabilities. Standard calculators often fail to handle the specific constraints of fixed-width integers, such as overflow behavior in 32-bit or 64-bit architecture.
The Bitwise Calculator handles these constraints by simulating specific data types used in C, C++, Rust, and Go. It supports operations like AND, OR, XOR, NOT, and bit shifts, taking into account the sign bit for signed integers (Two's Complement representation). This tool assists developers in debugging bitmasks, setting flags, and understanding binary data structures without manual conversion errors.
Formulas
Bitwise operations manipulate the underlying binary representation of numbers. The result depends heavily on the bit-width (N) and the signedness of the integer.
Two's Complement (Signed Integers):
For a signed N-bit integer, the value x is stored such that the most significant bit (MSB) indicates the sign. If the MSB is 1, the value is negative.
Value = −bN-1 × 2N-1 + N-2∑i=0 bi × 2i
Bitwise AND Truth Table:
Reference Data
| Operation | Operator | Logic | Example (A=1010, B=1100) |
|---|---|---|---|
| Bitwise AND | & | 1 if both bits are 1 | 1000 |
| Bitwise OR | | | 1 if either bit is 1 | 1110 |
| Bitwise XOR | ^ | 1 if bits are different | 0110 |
| Bitwise NOT | ~ | Inverts all bits | 0101 (for 4-bit) |
| Left Shift | << | Shifts bits left (multiply by 2) | 10100 (A << 1) |
| Right Shift | >> | Shifts bits right (divide by 2) | 0101 (A >> 1) |
| Zero-fill Right Shift | >>> | Shifts right, fills with 0 | Unsigned Only |