Bitwise & Two's Complement Calculator
Calculadora interativa de operações lógicas bit a bit e complemento de dois. Calcule AND, OR, XOR, NOT e deslocamentos de bits em inteiros com e sem sinal de 8, 16, 32 e 64 bits.
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.
Ferramentas de Conversão Relacionadas
Convert raw binary bitstreams into Decimal, Hexadecimal nibbles, and Octal UNIX permissions with step-by-step proofs.
Exercícios e Quiz de Matemática
Interactive math & CS problems with unpaywalled step-by-step proofs
Caderno de Problemas
Save problem sets & export clean PDF homework sheets
Tabelas de Consulta STEM
Sig Figs, IEEE-754 float anatomy & powers of 2
Calculadora Decimal
Add, subtract, multiply & divide with column arithmetic proofs
Calculadora de Frações
Add, subtract, multiply, divide & simplify fractions
Fração para Decimal
Convert fractions & mixed numbers to exact decimals & repeating cycles
Decimal para Fração
Mixed & improper fractions with GCD steps
Hexadecimal para Decimal
Convert Base-16 (0x) to Base-10 decimals with power expansion
Decimal para Hexadecimal
Base-16 hex with byte spacing & RGB preview
Conversor de Base N Arbitrária
Convert numbers between any radix base 2 through 36 with polynomial steps
Conversor IEEE-754 Ponto Flutuante
Interactive 32-bit & 64-bit IEEE-754 floating point visualizer
Binário para Decimal
Convert base-2 bits to base-10 decimal & fractions
Binário para Hexadecimal
Convert 4-bit nibbles to Base-16 hexadecimal (0x)
Binário para Octal
Convert 3-bit triplets to Base-8 octal & UNIX permissions
Decimal para Octal
Convert decimals to Base-8 octal & chmod permissions
Octal para Decimal
Convert Base-8 octal to decimal with powers of 8
Binário para Texto ASCII
Convert binary bits (0s and 1s) to readable ASCII text & characters
ASCII para Binário
Convert ASCII text and Unicode characters to 8-bit binary bits
ASCII para Decimal
Convert ASCII text and Unicode characters to decimal byte sequences
Decimal para ASCII
Convert decimal codes & byte arrays to ASCII text
Decimal para Binário
Base-2 bits & IEEE-754 32-bit float inspection
Decimal para Porcentagem
Percentage, basis points (bps) & gauge
Decimal para Polegadas
1/16″ to 1/64″ fractional inches & metric ruler
Calculadora de Horas Decimais e Ponto
Timecard punch hours, breaks, gross wages & FLSA rounding
Decimal para Minutos
HH:MM:SS timecodes & payroll work logs