Skip to content
CalculatorAtlas

Two's Complement Calculator

Tested

Two's-complement representation of an integer in a fixed bit width.

Tested, not yet published. The formula for this calculator is implemented and passes its automated checks. This page stays non-indexable until it is reviewed and published.

Results

Enter your values and press Calculate. Results appear here.

  • • Result

Quick answer

In n-bit two's complement a negative number x is stored as 2ⁿ + x. −5 in 8 bits is 256 − 5 = 251, binary 11111011, hex FB.

Enter a bit width and a decimal integer. The calculator returns the binary, hex and unsigned value.

Related tools: Binary Calculator: Add, subtract, multiply, divide or apply bitwise operations to binary numbers. Hex Calculator: Add, subtract or multiply hexadecimal numbers. Hex to Text Converter: Decode hexadecimal bytes as UTF-8 text.

How to use the Two's Complement Calculator

  1. Enter bit width (a whole number, between 2 and 64).
  2. Type decimal integer.
  3. Press Calculate to see the result, and use Reset to start again.
Inputs of the Two's Complement Calculator
InputWhat to enterAllowed values
Bit widthA whole number≥ 2, ≤ 64
Decimal integerText—

Formula and method

Formula

negative x is stored as 2ⁿ + x

IEEE-754 double precision; shown to the decimals indicated.

The value must fit in the signed range −2ⁿ⁻¹ … 2ⁿ−1.

Worked examples

These examples are verified: each one is an automated test case that the live calculator must reproduce exactly.

Example 1

Inputs: Bit width = 8; Decimal integer = -5.

Results of example 1
ResultValue
Binary11111011
HexadecimalFB
Unsigned value251

Example 2

Inputs: Bit width = 8; Decimal integer = 100.

Results of example 2
ResultValue
Binary01100100
Hexadecimal64
Unsigned value100

Example 3

Inputs: Bit width = 16; Decimal integer = -1.

Results of example 3
ResultValue
Binary1111111111111111
HexadecimalFFFF
Unsigned value65535

The first line is the headline result (binary). Below it the two's Complement Calculator lists hexadecimal and unsigned value, which describe the same case from other angles. IEEE-754 double precision; shown to the decimals indicated.

How to get it by hand

Write 5 as 00000101, invert the bits to 11111010 and add 1: 11111011.

Range

An 8-bit value runs from −128 to 127. Out-of-range values are rejected. The same bit pattern is 251 if read as unsigned.

How the result changes with bit width

Holding every other input at the first worked example, this table changes only bit width. It shows how sensitive the answer is to that one value; each row was produced by running this calculator.

How the result changes with bit width
Bit widthBinaryHexadecimalUnsigned value
41011B11
811111011FB251
161111111111111011FFFB65531
3211111111111111111111111111111011FFFFFFFB4294967291

What happens with invalid input

These messages are produced by the calculator itself, so you know what to fix.

  • Decimal integer: entering "300" shows "That does not fit in 8 bits." beside that field and no result.

Choosing between the Two's Complement Calculator and similar calculators

Each row shows what a related calculator on this site asks for and what it returns, so you can pick the one that matches your question.

Choosing between the Two's Complement Calculator and similar calculators
CalculatorYou enterIt returns
[Binary Calculator](/technology/binary-calculator/)first binary number, second binary number and operationResult
[Hex Calculator](/technology/hex-calculator/)first hex number, second hex number and operationResult
[Hex to Text Converter](/technology/hex-to-text/)hex bytesText
[Binary to Text Converter](/technology/binary-to-text/)binary bytesText
[Number Base Converter](/technology/base-calculator/)number, from base and to baseResult

Background: number systems

To convert a whole number from decimal to another base, divide repeatedly by the base and read the remainders backwards; to convert to decimal, multiply each digit by the base raised to its position (counting from 0 at the right) and add. Each hexadecimal digit equals exactly four bits and each octal digit three, so binary converts to hex by grouping bits in fours from the right.

255 in decimal is 11111111 in binary and FF in hexadecimal.

Assumptions and limitations

  • Out-of-range values are rejected

If a required value is empty, not a number, or outside its allowed range, the form marks that field with a message and shows no result instead of a misleading number. The automated checks deliberately try invalid entries for decimal integer to confirm this.

Frequently asked questions

What is −1 in 8 bits?

−1 in 8-bit two's complement is 11111111, which is 255 if read as unsigned.

Why use two's complement?

Addition works the same for signed and unsigned.

What is the range of 16 bits?

A 16-bit two's complement integer ranges from −32,768 to 32,767.

What does the Two's Complement Calculator calculate?

Two's-complement representation of an integer in a fixed bit width. It returns Binary, Hexadecimal and Unsigned value.

What formula does the Two's Complement Calculator use?

negative x is stored as 2ⁿ + x. The value must fit in the signed range −2ⁿ⁻¹ … 2ⁿ−1.

What do I need to enter in the two's Complement Calculator?

You enter Bit width and Decimal integer.

How is the result rounded or limited?

IEEE-754 double precision; shown to the decimals indicated. Out-of-range values are rejected.

What is an example of a two's Complement result?

With bit width 8 and decimal integer -5, the binary is 11111011.

Where does the method come from?

The method follows: Positional numeral systems and two's-complement representation: see IEEE 754-2019 and ISO/IEC 9899 (C standard) for the integer and floating-point formats computers use; the arithmetic itself is base-b place-value expansion.

Sources

  • Positional numeral systems and two's-complement representation: see IEEE 754-2019 and ISO/IEC 9899 (C standard) for the integer and floating-point formats computers use; the arithmetic itself is base-b place-value expansion

Content last reviewed 2026-11-04. Formulas and worked examples are checked by automated tests against independently computed values.