Convert between decimal and two's complement binary representation. Calculate two's complement for signed integers with step-by-step solutions for 4-bit, 8-bit, 12-bit, 16-bit, 24-bit, 32-bit, and 64-bit formats. Free online calculator.
Convert between decimal and two's complement binary representation with step-by-step solutions:
Note: Enter a signed integer between -128 and 127
Ready to Calculate
Enter a decimal or binary value to calculate two's complement
Copy the code below to embed this calculator on your website
Two's complement is the most widely used method for representing signed integers in binary form in computer systems. Whether you're a computer science student learning binary arithmetic, a programmer debugging signed number operations, or an engineer working with digital systems, understanding two's complement is essential for working with signed binary numbers. This comprehensive guide will walk you through everything you need to know about two's complement, from basic concepts to practical applications.
At its core, two's complement allows computers to represent both positive and negative integers using binary digits. Our Two's Complement Calculator at the top of this page makes these conversions instant and accurate, but understanding the underlying principles will help you solve complex binary arithmetic problems and make informed decisions in digital systems design. We'll explore the mathematical concepts, provide practical examples, and clarify common points of confusion.
Our Two's Complement Calculator is designed for simplicity and accuracy. Follow these steps to convert between decimal and two's complement binary:
The calculator includes built-in validation to ensure values are within the valid range for the selected bit width.
Two's complement is a method for representing signed integers in binary that simplifies arithmetic operations in computers. The key advantage is that addition and subtraction can be performed using the same hardware for both signed and unsigned numbers.
For an n-bit two's complement representation:
Positive numbers in two's complement are represented the same way as unsigned binary numbers. The most significant bit (MSB) is 0.
Example: +5 in 8-bit = 00000101
Negative numbers are represented by taking the two's complement of the absolute value. The MSB is 1 for negative numbers.
Example: -5 in 8-bit = 11111011
To convert a negative decimal number to two's complement binary, follow these steps:
First, convert the absolute value of the number to binary.
Example: For -5, convert 5 to binary: 101
Pad the binary number with leading zeros to reach the desired bit width.
5 in 8-bit: 00000101
Flip all 0s to 1s and all 1s to 0s.
00000101 → 11111010
Add 1 to the inverted binary number to get the two's complement.
11111010 + 1 = 11111011
The result 11111011 is the two's complement representation of -5 in 8-bit format.
To convert a two's complement binary number back to decimal:
Simply convert the binary number to decimal as you would with unsigned binary.
00000101 = 5
The process is the reverse of creating two's complement:
11111011 → 00000100 → 00000101 = 5 → -5
Two's complement has several important mathematical properties:
Each integer in the range has a unique two's complement representation. There is no ambiguity between +0 and -0 (both are represented as all zeros).
Addition and subtraction can be performed using the same binary addition circuit, regardless of whether the numbers are signed or unsigned.
Overflow occurs when the result of an operation exceeds the representable range. In two's complement, overflow can be detected by checking if the sign of the result differs from what would be expected.
To extend a signed number to more bits, copy the MSB (sign bit) to all new higher-order bits.
8-bit: 11111011 (-5) → 16-bit: 1111111111111011 (-5)
Two's complement is used in numerous real-world scenarios:
Used in educational contexts and simple embedded systems. Range: -8 to 7.
Commonly used in embedded systems and microcontrollers. Range: -128 to 127.
Used in some specialized applications and digital signal processing. Range: -2,048 to 2,047.
Used in many programming languages as "short" integers. Range: -32,768 to 32,767.
Used in audio processing and some specialized applications. Range: -8,388,608 to 8,388,607.
Standard integer size in most modern systems. Range: -2,147,483,648 to 2,147,483,647.
Used for large integer calculations and in modern 64-bit systems. Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
It's important to understand how two's complement compares to other signed number representations:
Advantages: Simple arithmetic, no negative zero, efficient hardware implementation.
Disadvantages: Has negative zero, requires end-around carry for addition.
Disadvantages: More complex arithmetic, has negative zero, requires separate handling of sign bit.
Overflow occurs when the result of an arithmetic operation cannot be represented in the available number of bits. For example, adding 127 + 1 in 8-bit two's complement results in -128 (overflow).
In two's complement arithmetic, the carry-out from the MSB position indicates overflow for unsigned operations, while the XOR of carry-in and carry-out indicates overflow for signed operations.
Two's complement multiplication and division require special algorithms that handle the sign bit correctly.
When working with two's complement in programming and digital systems:
Two's complement simplifies arithmetic operations. Addition and subtraction work the same way for signed and unsigned numbers, requiring less complex hardware. It also eliminates the ambiguity of negative zero.
The range is from -2^(n-1) to 2^(n-1)-1. For example, 8-bit two's complement ranges from -128 to 127.
Zero is represented as all zeros (00000000 in 8-bit). There is only one representation for zero, unlike one's complement which has both +0 and -0.
Adding 1 to the maximum positive value (e.g., 127 + 1 in 8-bit) results in overflow, producing the minimum negative value (-128). This is called wraparound.
Yes, you can directly interpret the binary value, but for negative numbers (MSB = 1), you need to subtract 2^n from the unsigned interpretation to get the correct signed value.
Because zero takes up one value in the positive range. In 8-bit, we have 128 negative values (-128 to -1), zero (0), and 127 positive values (1 to 127), totaling 256 possible values.
Mastering two's complement is essential for understanding how computers represent and manipulate signed integers. Whether you're working with computer architecture, programming, or digital systems design, understanding the principles of two's complement helps you approach problems with confidence and accuracy.
Our Two's Complement Calculator provides instant, accurate conversions for any signed integer, but the mathematical concepts behind it are equally important. By understanding both the calculator and the underlying principles, you'll be well-equipped to work with signed binary numbers in any context.
Ready to explore more mathematical concepts? Check out our Binomial Coefficient Calculator for combinatorics calculations, or use our Remainder Calculator for modular arithmetic operations.
Find the slope of a line using two points or from a linear equation in various forms.
AlgebraCalculate parabola properties including vertex, focus, directrix, and axis of symmetry.
AlgebraSolve the classic diamond problem to find two numbers from their sum and product.
AlgebraSolve proportions and ratios instantly using cross multiplication method.
AlgebraConvert linear equations from standard form to slope-intercept form instantly.
AlgebraGet instant results with our optimized calculation engine
Precise calculations you can trust for any project
Works perfectly on all devices and screen sizes