Two's Complement Calculator Convert between Decimal, Binary, 1's Complement, and 2's Complement

Conversion Result

Two's Complement Calculator: A Programmer's Essential Tool

Easily convert between decimal and binary with full support for signed numbers. Instantly calculate 1's and 2's complement. Essential for computer architecture and low-level programming.

✨ Converter Features

  • Decimal → Binary: Supports positive and negative numbers
  • Binary → Decimal: Signed and unsigned support
  • 1's Complement Calculation: Bitwise inversion
  • 2's Complement Calculation: 1's complement + 1
  • Reverse Conversion: From complement to original binary
  • Bit Lengths: 8, 16, 32, 64 bits

💡 What is Two's Complement?

Two's complement is the standard method for representing signed numbers in modern computers.

1's Complement: Inverts all bits (0→1, 1→0)

2's Complement: 1's complement + 1

Example (8-bit):

  • Original Binary: 00001010 (+10)
  • 1's Complement: 11110101
  • 2's Complement: 11110110 (-10)

🛠️ Why Use Two's Complement?

Hardware Advantages:

  • Unified Operations: Addition and subtraction use the same circuit
  • Single Zero: There is only one representation of 0 (no +0/-0)
  • Symmetric Range: For n bits: -2ⁿ⁻¹ to +2ⁿ⁻¹-1
  • Simple Comparison: Can be compared directly as unsigned integers

Subtraction Example with 2's Complement:

A - B = A + (-B) = A + 2's_complement(B)

5 - 3 = 5 + (-3) = 0101 + 1101 = 0010 = 2

💻 Applications in Programming

  • C/C++: int, short, long types use two's complement
  • Java: All integer types are signed (two's complement)
  • Python: Arbitrary-precision integers, internally uses two's complement
  • Bitwise Operations: Shifts, masks, XOR

Reference: Two's Complement - Wikipedia

Methods to convert decimal to binary in various programming languages

JavaInteger.toBinaryString(decimal_number)
JavaScriptlet binary = decimal_number.toString(2);
Microsoft .NET / C#string binary = Convert.ToString(decimal_number, 2);
Pythonbinary = bin(decimal_number)[2:]
Rubybinary = decimal_number.to_s(2)
Go import strconv
binary := strconv.FormatInt(decimal_number, 2)
X