Last updated: Jan 26, 2026
Two's Complement Calculator
Welcome to our comprehensive two’s complement calculator and converter. This online tool helps you understand binary representation, perform signed binary arithmetic, and convert between decimal and two’s complement notation. Whether you’re working with 8-bit, 16-bit, 32-bit, or 64-bit two’s complement numbers, our calculator provides accurate results for computer arithmetic and digital electronics applications.
What is Two’s Complement?
Two’s complement is a mathematical operation and number representation system used in digital logic circuits and computer architecture to represent signed integers (both positive numbers and negative numbers) in binary. This method is the most common way computers handle negative binary numbers and perform binary subtraction operations.
In the two’s complement representation, the most significant bit (MSB) serves as the sign bit: 0 indicates a positive number, while 1 indicates a negative number. This signed number representation is superior to signed magnitude and one’s complement alternatives because it provides a unique representation for zero and simplifies hardware implementation of arithmetic operations.
The two’s complement system is fundamental to computer arithmetic, data representation, and number systems in computer science. It’s used extensively in programming languages like C++, Python, and JavaScript, as well as in assembly language and embedded systems coding. Understanding bitwise operations and how two’s complement works is essential for hardware design validation, software implementation, and working with integer representation in fixed-point numbers.
How to Find Two’s Complement?
Calculating the two’s complement of a number involves a simple two-step process using bitwise inversion method:
- Invert all bits: Change every 0 to 1 and every 1 to 0 (this is called one’s complement or bitwise inversion)
- Add one: Add 1 to the result from step 1
Example: Finding 2’s Complement of 5 (8-bit)
Step 1: Start with the binary representation of 5
Step 2: Invert all bits (one’s complement)
Step 3: Add 1 to the result
Example: 2’s Complement of 23 (8-bit)
Binary of 23: 0001 0111
Invert bits: 1110 1000
Add 1: 1110 1001 (This represents -23)
Example: 2’s Complement of 6 (4-bit)
Binary of 6: 0110
Invert bits: 1001
Add 1: 1010 (This represents -6 in 4-bit)
How Two’s Complement Works
The two’s complement system works by using radix complement arithmetic, which is a form of modular arithmetic application. In this machine representation format, the range of representable numbers depends on the number of bits used:
- 4-bit two’s complement: Range from -8 to +7
- 5-bit two’s complement: Range from -16 to +15
- 8-bit two’s complement: Range from -128 to +127
- 16-bit two’s complement: Range from -32,768 to +32,767
- 32-bit two’s complement: Range from -2,147,483,648 to +2,147,483,647
- 64-bit two’s complement: Range from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
The formula for the number range in n-bit two’s complement is: -2(n-1) to 2(n-1) – 1
For Two’s Complement Addition/Subtraction:
One of the most powerful features of two’s complement notation is that it enables simplifying subtraction operations by converting them to addition. This efficient digital subtraction method is why two’s complement is the standard in computer architecture basics.
Addition: Simply add the two binary numbers normally. If there’s a carry out from the most significant bit, discard it (assuming no overflow).
Example: 5 + (-3) in 8-bit two’s complement
Subtraction: To subtract B from A (A – B), take the two’s complement of B and add it to A. This is how computers perform binary subtraction using addition circuitry.
Example: 7 – 4 in 8-bit two’s complement
Instead of direct subtraction, compute 7 + (-4):
Two’s Complement Converter in Practice
Our online two’s complement tool can handle various conversion tasks essential for digital electronics, computer programming, and hardware implementation:
- Decimal to two’s complement: Convert any decimal number to its binary two’s complement representation
- Binary to two’s complement: Convert positive binary numbers to their negative equivalents
- Two’s complement to decimal: Decode signed binary numbers back to decimal values
- Two’s complement addition calculator: Perform binary arithmetic operations with automatic overflow detection
- Multi-bit support: Works with 4-bit, 5-bit, 8-bit, 9-bit, 10-bit, 16-bit, 24-bit, 32-bit, and 64-bit representations
This complement calculator online is particularly useful for:
- Students learning about number systems and computer architecture
- Programmers working with low-level bit manipulation
- Hardware engineers designing digital logic circuits
- Assembly language programmers handling signed integers
- Embedded systems developers managing data type representation
Turning Two’s Complement to Decimal
Converting two’s complement binary to decimal (complemented signed integer to decimal) can be done using two different methods:
Method 1: Check the Sign Bit
This method involves examining the most significant bit to determine if the number is positive or negative:
- Check the MSB (leftmost bit):
- If MSB = 0: The number is positive. Simply convert the binary to decimal normally.
- If MSB = 1: The number is negative. Proceed to step 2.
- For negative numbers:
- Invert all bits (change 0s to 1s and 1s to 0s)
- Add 1 to the result
- Convert the resulting binary to decimal
- Add a negative sign to the final answer
Example: Convert 1111 1011 to decimal (8-bit)
Step 1: MSB is 1, so this is a negative number
Step 2: Invert all bits: 0000 0100
Step 3: Add 1: 0000 0101
Step 4: Convert to decimal: 5
Step 5: Add negative sign: -5
Method 2: Weighted Sum with Negative MSB
This method treats the most significant bit as having a negative weight:
- Assign powers of 2 to each bit position (right to left): 20, 21, 22, etc.
- For the MSB, use a negative weight: -2(n-1) where n is the number of bits
- Multiply each bit by its corresponding weight
- Sum all the values to get the decimal result
Example: Convert 1111 1011 to decimal (8-bit)
Signed Binary to Decimal Table
This table shows the relationship between signed binary (8-bit two’s complement) and decimal values, demonstrating how negative number handling works in computer systems:
| Binary (8-bit) | Two’s Complement Decimal | Unsigned Decimal |
|---|---|---|
| 0111 1111 | +127 | 127 |
| 0111 1110 | +126 | 126 |
| 0000 0010 | +2 | 2 |
| 0000 0001 | +1 | 1 |
| 0000 0000 | 0 | 0 |
| 1111 1111 | -1 | 255 |
| 1111 1110 | -2 | 254 |
| 1111 1101 | -3 | 253 |
| 1000 0010 | -126 | 130 |
| 1000 0001 | -127 | 129 |
| 1000 0000 | -128 | 128 |
Notice that the bit pattern for -1 (1111 1111) appears as 255 in unsigned representation. This illustrates the fundamental difference between signed and unsigned integers in data representation.
Two’s Complement Table
Here’s a comprehensive lookup table showing decimal numbers and their two’s complement values across different bit widths:
| Decimal | 4-bit Two’s Complement | 8-bit Two’s Complement | 16-bit Two’s Complement |
|---|---|---|---|
| 7 | 0111 | 0000 0111 | 0000 0000 0000 0111 |
| 6 | 0110 | 0000 0110 | 0000 0000 0000 0110 |
| 5 | 0101 | 0000 0101 | 0000 0000 0000 0101 |
| 1 | 0001 | 0000 0001 | 0000 0000 0000 0001 |
| 0 | 0000 | 0000 0000 | 0000 0000 0000 0000 |
| -1 | 1111 | 1111 1111 | 1111 1111 1111 1111 |
| -2 | 1110 | 1111 1110 | 1111 1111 1111 1110 |
| -5 | 1011 | 1111 1011 | 1111 1111 1111 1011 |
| -6 | 1010 | 1111 1010 | 1111 1111 1111 1010 |
| -8 | 1000 | 1111 1000 | 1111 1111 1111 1000 |
| -37 | N/A (out of range) | 1101 1011 | 1111 1111 1101 1011 |
FAQs
What is the Two’s Complement?
The two’s complement is both a mathematical operation and a method for representing signed integers (positive and negative numbers) in binary number systems. It’s the most widely used technique in computer architecture for representing negative integers because it allows computers to perform subtraction using the same hardware circuits used for addition.
To obtain the two’s complement of a binary number, you invert all the bits (change 0s to 1s and 1s to 0s) and then add 1 to the result. This complemented signed integer format is essential for binary arithmetic operations in digital logic and computing.
How Do I Calculate the Two’s Complement of a Number?
Calculating the two’s complement involves these steps:
- Convert the absolute value of your number to binary
- Ensure you have the correct bit width (pad with leading zeros if needed)
- If the number is positive, you’re done – that’s already the two’s complement representation
- If the number is negative:
- Take the binary of the absolute value
- Invert all bits (perform bitwise NOT operation)
- Add 1 to the result
You can also use our online two’s complement calculator above to perform these calculations automatically for any bit width, including 4-bit two’s complement calculator, 5-bit, 8-bit, 10-bit, 16-bit, 24-bit, 32-bit, and 64-bit formats.
What are the Disadvantages of the Two’s Complement Notation?
While two’s complement is the standard for representing signed integers, it has a few limitations:
- Asymmetric Range: The range is not perfectly balanced – there’s one more negative number than positive numbers (e.g., 8-bit ranges from -128 to +127, not -127 to +127). This can sometimes be counterintuitive.
- No Obvious Sign: The binary representation doesn’t make it immediately obvious whether a number is positive or negative without knowing the context (signed vs. unsigned interpretation).
- Overflow Complexity: Detecting overflow and underflow conditions requires additional logic in hardware and software, as the result might wrap around unexpectedly.
- Non-intuitive for Humans: The binary negative conversion is less intuitive than signed magnitude notation for human readers.
- Multiplication Complexity: While addition and subtraction are simple, multiplication and division operations are more complex in two’s complement than with unsigned integers.
Despite these disadvantages, two’s complement remains the dominant method because its advantages (particularly simplified hardware for addition and subtraction) far outweigh these drawbacks for practical computer implementation.
What is the 8-bit Two’s Complement Notation of -37?
To find the 8-bit two’s complement of -37:
Answer: The 8-bit two’s complement notation of -37 is 1101 1011
You can verify this using Method 2 for conversion back:
Binary to Decimal
Understanding binary to decimal conversion is fundamental to working with two’s complement notation. Here’s how to convert binary numbers to decimal:
For Unsigned Binary Numbers:
- Write down the binary number
- Assign powers of 2 to each bit position from right to left: 20, 21, 22, 23, etc.
- Multiply each bit (0 or 1) by its corresponding power of 2
- Sum all the products to get the decimal value
Example: Convert 1010 to decimal
For Signed Binary (Two’s Complement):
Use either Method 1 or Method 2 described in the “Turning Two’s Complement to Decimal” section above. Our binary calculator and two’s complement converter can handle both signed and unsigned conversions automatically.
Converting Decimal to Binary:
- For positive numbers: Use repeated division by 2, recording remainders
- For negative numbers in two’s complement: Convert the absolute value to binary, then apply the two’s complement operation (invert and add 1)
These conversions are essential for understanding number systems in computer science, working with boolean algebra, and implementing algorithms in programming languages.
Reference
Two’s complement is a cornerstone concept in computer science and digital electronics. Here are some areas where understanding two’s complement is particularly important:
- Programming Languages: Languages like C++, Python, JavaScript, and Assembly Language all use two’s complement for integer representation internally.
- Computer Architecture: CPU design, ALU (Arithmetic Logic Unit) implementation, and instruction set architecture rely on two’s complement arithmetic.
- Digital Logic: Logic gates, adders, subtractors, and other digital circuits are designed around two’s complement operations.
- Data Structures: Understanding two’s complement helps with bit manipulation, implementing custom integer types, and optimizing code.
- Embedded Systems: Microcontrollers and embedded systems coding frequently work directly with two’s complement values in memory and registers.
- Floating-Point Numbers: While IEEE 754 uses a different system for the exponent and mantissa, understanding two’s complement helps grasp how floating-point numbers work.
- Network Protocols: Many network protocols use two’s complement for checksums and data integrity verification.
- Cryptography: Some cryptographic algorithms involve bitwise operations on two’s complement integers.
Math Tools
Our suite of mathematical tools and calculators can help you with various calculations related to number systems and computer arithmetic:
- Two’s Complement Calculator: Convert between decimal and two’s complement (this tool)
- Binary Calculator: Perform binary number operations (addition, subtraction, multiplication, division)
- Binary to Decimal Converter: Convert binary numbers to decimal and vice versa
- One’s Complement Calculator: Calculate one’s complement for comparison with two’s complement
- Hexadecimal Converter: Convert between binary, decimal, and hexadecimal
- Bit Shift Calculator: Perform logical and arithmetic bit shifts
- Boolean Algebra Calculator: Evaluate boolean expressions and logic operations
- Binary Subtraction Calculator: Specialized tool for binary subtraction using various methods
- 2’s Complement Addition Calculator: Perform addition with automatic overflow detection
- Signed Binary Calculator: Work with signed binary numbers in various formats
These online calculators are designed for students, engineers, programmers, and anyone working with binary numbers, digital electronics, or computer systems. They support multiple bit widths and provide step-by-step solutions to help you understand the underlying mathematics.
Other Languages
This two’s complement calculator and educational content is available in multiple languages to serve our global community of learners, developers, and engineers:
- English – Two’s Complement Calculator
- Spanish – Calculadora de Complemento a Dos
- French – Calculateur de Complément à Deux
- German – Zweierkomplement-Rechner
- Portuguese – Calculadora de Complemento de Dois
- Italian – Calcolatore del Complemento a Due
- Russian – Калькулятор Дополнительного Кода
- Chinese (Simplified) – 二进制补码计算器
- Japanese – 2の補数計算機
- Korean – 2의 보수 계산기
- Arabic – حاسبة المتمم الثنائي
- Hindi – टू’ज़ कॉम्प्लिमेंट कैलकुलेटर
We continually expand our language support to make computer science and digital electronics education accessible worldwide. The mathematical principles of two’s complement remain the same across all languages, making it a universal language in computer architecture.
About This Tool
This free online two’s complement calculator is designed to help students, programmers, and engineers understand and work with binary arithmetic and signed integer representation. Whether you need to calculate the 2’s complement of 5, 2’s complement of 9, or work with larger values in 16-bit, 32-bit, or 64-bit formats, our tool provides accurate results instantly.
Features include:
- Support for all common bit widths (4, 5, 8, 9, 10, 16, 24, 32, 64-bit)
- Decimal to two’s complement conversion
- Two’s complement to decimal conversion
- Binary to two’s complement conversion
- Step-by-step calculations
- Overflow and underflow detection
- Works on Windows Calculator-compatible format
- Compatible with Excel formulas (2’s complement calculator in Excel)
Whether you’re learning about computer architecture basics, implementing algorithms in C++ or Assembly language, designing hardware for embedded systems, or just need to quickly convert between number systems, this complement calculator online provides the functionality you need.
The tool follows standard IEEE conventions and produces results compatible with most programming languages and hardware platforms, making it suitable for both educational purposes and professional development work.
Basic Conversion
Enter a decimal number (e.g., -42 or 127)
Arithmetic Operations
Range Analysis & Bit Comparison
Common Examples & Scenarios
Binary: 00100101 (37 in binary)
Invert: 11011010 (one's complement)
Add 1: 11011011 (two's complement)
-5 = 1011, -3 = 1101
1011 + 1101 = 11000
Result: 1000 = -8 (Correct!)
0111 1111 + 0000 0001
= 1000 0000 = -128
⚠️ Overflow! (positive + positive = negative)
• The leftmost bit (MSB) is the sign bit: 0 = positive, 1 = negative
• Two's complement = One's complement + 1
• Overflow occurs when adding same-sign numbers yields opposite sign
• Range for n-bit: -2^(n-1) to 2^(n-1) - 1
Value = -2^(n-1) × MSB + Σ(2^i × bit_i)
Practical Applications
• CPU registers for integer arithmetic
• Programming languages (int, short, long types)
• Digital signal processing
• Embedded systems and microcontrollers
✓ Addition/subtraction use same circuitry
✓ Simple overflow detection
✓ Efficient hardware implementation
✓ Standard in modern computers
⚠️ Unexpected negative results
⚠️ Type casting issues
⚠️ Forgetting sign extension
⚠️ Assuming symmetric positive/negative range
Quick Reference: 4-bit Two's Complement
| Binary | Decimal | Hex |
|---|
