Two’s Complement Calculator
Get the binary form of negatives.
Result
How it is calculated
Given a whole number n and a width of w bits, the tool first checks that n fits the range −2w−1 ≤ n ≤ 2w−1 − 1. For a negative n it computes n + 2w, which is exactly the invert-and-add-one rule. Positive numbers and zero are written as ordinary binary. The result is padded with leading zeros to exactly w digits. The width must be a whole number from 2 to 32. Anything else gives no result: a fractional number, a width of 1 or 33, or a value outside the range for that width (for example 128 or −129 with 8 bits). The output is a bit string, not a decimal value, and it has no unit.
Worked example
Write −42 in 8 bits. The allowed range for 8 bits is −128 to 127, so −42 fits. Start from +42 = 00101010. Invert every bit to get 11010101, then add 1 to get 11010110. The same answer comes from the formula: −42 + 28 = 256 − 42 = 214, and 214 in binary is 11010110. The tool prints 11010110. The leading 1 marks the number as negative.
Common mistakes
- Choosing a width that is too small. With 8 bits the range ends at 127 and −128, so 128 or −129 returns nothing; widen to 16 bits for those.
- Reading the result as an unsigned number. 11010110 is −42 in 8-bit two's complement but 214 if you treat it as unsigned.
- Forgetting the width. The same −1 is 11 in 2 bits, 1111 in 4 bits and 32 ones in 32 bits, so the bit count must match your system.
- Entering a binary or hex string as the number. The box expects an ordinary decimal integer, such as −42.
- Expecting a symmetric range. Two's complement has one more negative value than positive: −128 exists in 8 bits (10000000), but +128 does not.
About this calculator
Two's complement is the standard method computers use to represent signed, positive and negative, integers in binary: to find the two's complement of a number, you invert every bit of its binary representation, called the one's complement, and then add 1. This scheme lets a single set of binary addition circuitry handle both addition and subtraction without any special-case logic, since subtracting a number is the same as adding its two's complement.
Virtually every modern CPU, from microcontrollers to desktop processors, uses two's complement internally to store signed integers because it has exactly one representation for zero, unlike sign-magnitude or one's-complement encoding which have both a “positive zero” and “negative zero,” and because overflow behavior is well-defined and consistent, making it foundational knowledge for computer science students, embedded systems engineers, and anyone debugging low-level binary or hexadecimal data.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments