Bitwise & Two's Complement Calculator
Interactive bitwise logic engine and two's complement signed integer analyzer. Toggle individual bits, evaluate AND, OR, XOR, NOT, and bit shifts, and inspect mathematical proofs.
Two's Complement Mathematical Weight Formula
In an N-bit two's complement integer, the MSB (Bit 7) carries a negative weight of -2N-1, and all other bits carry positive powers of 2 (+2i):
Step-by-Step Calculation Breakdown
Bitwise Operations & Logic Reference Guide
Master truth tables, bitmasking techniques, and hardware register manipulation.
Standard Bitwise Operator Truth Tables
Binary Bit Logic| Operation | Symbol / Syntax | Logic Rule | Example |
|---|---|---|---|
| AND (&) | A & B | 1 only if both bits are 1 | 1100 & 1010 = 1000 (8) |
| OR (|) | A | B | 1 if at least one bit is 1 | 1100 | 1010 = 1110 (14) |
| XOR (^) | A ^ B | 1 if bits are different (parity) | 1100 ^ 1010 = 0110 (6) |
| NOT (~) | ~A | Invert all bits (One's complement) | ~00101010 = 11010101 (-43 signed) |
| NAND | ~(A & B) | Inverted AND: 0 only if both are 1 | ~(1100 & 1010) = 0111 (7) |
| NOR | ~(A | B) | Inverted OR: 1 only if both are 0 | ~(1100 | 1010) = 0001 (1) |
| Left Shift (<<) | A << n | Shift bits left, fills 0 on right (multiplies by 2ⁿ) | 00000101 << 2 = 00010100 (20) |
| Arithmetic Right Shift (>>) | A >> n | Shift right, preserves sign bit MSB (divides by 2ⁿ) | 11110110 >> 1 = 11111011 (-5) |
| Logical Right Shift (>>>) | A >>> n | Shift right, fills 0 into MSB (zero-fill) | 11110110 >>> 1 = 01111011 (123) |
Bitmasking & Permissions
Operating systems and graphics engines store multiple boolean flags within a single byte using masks (e.g. flags & READ_ONLY).
XOR Parity & Cryptography
XOR has the property (A ^ B) ^ B = A, making it the bedrock of stream ciphers, RAID-5 disk parity recovery, and in-place variable swaps.
Color Packing (RGBA 32-bit)
Graphics cards pack Red, Green, Blue, and Alpha into one 32-bit integer: (R << 24) | (G << 16) | (B << 8) | A.
Frequently Asked Questions
Everything you need to know about decimal conversions, accuracy, and formulas.
01What is Two's Complement in binary computing?▼
Two's complement is the universal mathematical method computers use to represent signed integers (positive and negative numbers). In an N-bit system, the most significant bit (MSB) has a negative positional weight of -2ⁿ⁻¹, while all remaining bits have positive weights (+2ⁱ). To negate a number in two's complement, invert all bits (one's complement) and add 1.
02What is the difference between Arithmetic Shift (>>) and Logical Shift (>>>)?▼
Arithmetic right shift (>>) preserves the sign bit (MSB), meaning if the number is negative, 1s are shifted in from the left to preserve negativity. Logical right shift (>>>) always shifts in zeros from the left regardless of the sign, treating the bit pattern strictly as an unsigned integer.
03Why does ~0 equal -1 in two's complement?▼
Zero in 8-bit binary is 00000000. Inverting every bit gives 11111111. In two's complement, the MSB has weight -128, and the remaining 7 bits sum to +127. Calculating -128 + 127 = -1. Therefore, ~0 always equals -1 in any word size.
04How do bitwise masks work in software engineering?▼
A bitmask uses bitwise AND (&) to query specific flags, OR (|) to set flags, and XOR (^) to toggle flags. For example, testing if an integer is odd is performed with (n & 1) === 1, and clearing the lower 4 bits is achieved with n & 0xF0.
Related Conversion Tools
Convert raw binary bitstreams into Decimal, Hexadecimal nibbles, and Octal UNIX permissions with step-by-step proofs.
Math Practice & Quiz
Interactive math & CS problems with unpaywalled step-by-step proofs
Student Notebook
Save problem sets & export clean PDF homework sheets
STEM Cheat Sheets
Sig Figs, IEEE-754 float anatomy & powers of 2
Decimal Calculator
Add, subtract, multiply & divide with column arithmetic proofs
Fraction Calculator
Add, subtract, multiply, divide & simplify fractions
Fraction to Decimal
Convert fractions & mixed numbers to exact decimals & repeating cycles
Decimal to Fraction
Mixed & improper fractions with GCD steps
Hexadecimal to Decimal
Convert Base-16 (0x) to Base-10 decimals with power expansion
Decimal to Hex
Base-16 hex with byte spacing & RGB preview
Base-N Radix Converter
Convert numbers between any radix base 2 through 36 with polynomial steps
IEEE-754 Floating-Point Converter
Interactive 32-bit & 64-bit IEEE-754 floating point visualizer
Binary to Decimal
Convert base-2 bits to base-10 decimal & fractions
Binary to Hexadecimal
Convert 4-bit nibbles to Base-16 hexadecimal (0x)
Binary to Octal
Convert 3-bit triplets to Base-8 octal & UNIX permissions
Decimal to Octal
Convert decimals to Base-8 octal & chmod permissions
Octal to Decimal
Convert Base-8 octal to decimal with powers of 8
Binary to ASCII Text
Convert binary bits (0s and 1s) to readable ASCII text & characters
ASCII to Binary
Convert ASCII text and Unicode characters to 8-bit binary bits
ASCII to Decimal
Convert ASCII text and Unicode characters to decimal byte sequences
Decimal to ASCII
Convert decimal codes & byte arrays to ASCII text
Decimal to Binary
Base-2 bits & IEEE-754 32-bit float inspection
Decimal to Percent
Percentage, basis points (bps) & gauge
Decimal to Inches
1/16″ to 1/64″ fractional inches & metric ruler
Decimal Hours & Timecard Calculator
Timecard punch hours, breaks, gross wages & FLSA rounding
Decimal to Minutes
HH:MM:SS timecodes & payroll work logs