2s Complement Calculator - Binary Two's Complement Online
Result
—
Binary 2's Complement Calculator
The Binary 2's Complement Calculator instantly computes the two's complement of any binary number. This free online tool is essential for computer science students, digital electronics engineers, assembly language programmers, and anyone working with signed binary number representations.
Two's complement is the standard method used by modern computers to represent signed (positive and negative) integers in binary. It simplifies arithmetic operations and eliminates the need for separate circuits to handle negative numbers.
What is Two's Complement?
Two's complement is the most widely used method of representing signed integers in binary. In an N-bit two's complement system, positive numbers are represented identically to unsigned binary, while negative numbers are represented by inverting all bits (1's complement) and adding 1 to the result.
How to Calculate Two's Complement
- Write the binary number.
- Invert all bits (0 becomes 1, 1 becomes 0) — this gives the 1's complement.
- Add 1 to the 1's complement result.
- The result is the two's complement.
Two's Complement Formula
Two's Complement = 1's Complement + 1 OR equivalently: Two's Complement = (2^N) - Value where N is the number of bits
Example
Binary = 1011 (4-bit) Step 1: Original → 1011 Step 2: Invert → 0100 (1's complement) Step 3: Add 1 → 0101 (2's complement) Value represented = -5
Two's Complement Conversion Table
| 4-bit Binary | Unsigned Decimal | Signed Decimal (2's comp) |
|---|---|---|
| 0000 | 0 | 0 |
| 0001 | 1 | +1 |
| 0111 | 7 | +7 |
| 1000 | 8 | -8 |
| 1001 | 9 | -7 |
| 1010 | 10 | -6 |
| 1011 | 11 | -5 |
| 1100 | 12 | -4 |
| 1101 | 13 | -3 |
| 1110 | 14 | -2 |
| 1111 | 15 | -1 |
Applications of Two's Complement
- Signed Integer Representation in CPUs
- Assembly Language and Machine Code
- ALU (Arithmetic Logic Unit) Design
- Computer Architecture and Processor Design
- Embedded Systems Programming
- Fixed-Point Arithmetic
- Digital Signal Processing (DSP)
- Computer Science and Programming Education
Programming Examples
Python # Two's complement of 1011 in 4 bits n = 0b1011 bits = 4 twos = (~n & (2**bits - 1)) + 1 bin(twos) Output '0b101' (i.e., 0101)
C
// Signed int automatically uses 2's complement
int x = -5;
printf("%d", x);
Frequently Asked Questions
What is a two's complement?
Two's complement is the standard binary representation for signed integers. It is computed by inverting all bits of a binary number and then adding 1 to the result.
How do I convert binary to two's complement?
Invert all bits of the binary number to get the 1's complement, then add 1. The result is the two's complement representation.
What is the two's complement of 1011?
The 1's complement of 1011 is 0100. Adding 1 gives 0101, which represents -5 in a 4-bit signed system.
Why do computers use two's complement?
Two's complement simplifies hardware design because addition and subtraction work the same way for both positive and negative numbers, eliminating the need for special subtraction circuits.
What is the range of an 8-bit two's complement number?
An 8-bit two's complement number can represent values from -128 to +127.
Is this Binary 2's Complement Calculator free?
Yes. This online Binary 2's Complement Calculator is completely free to use and works directly in your browser without any installation or registration.