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
- Enter bit width (a whole number, between 2 and 64).
- Type decimal integer.
- Press Calculate to see the result, and use Reset to start again.
| Input | What to enter | Allowed values |
|---|---|---|
| Bit width | A whole number | ≥ 2, ≤ 64 |
| Decimal integer | Text | — |
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.
| Result | Value |
|---|---|
| Binary | 11111011 |
| Hexadecimal | FB |
| Unsigned value | 251 |
Example 2
Inputs: Bit width = 8; Decimal integer = 100.
| Result | Value |
|---|---|
| Binary | 01100100 |
| Hexadecimal | 64 |
| Unsigned value | 100 |
Example 3
Inputs: Bit width = 16; Decimal integer = -1.
| Result | Value |
|---|---|
| Binary | 1111111111111111 |
| Hexadecimal | FFFF |
| Unsigned value | 65535 |
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.
| Bit width | Binary | Hexadecimal | Unsigned value |
|---|---|---|---|
| 4 | 1011 | B | 11 |
| 8 | 11111011 | FB | 251 |
| 16 | 1111111111111011 | FFFB | 65531 |
| 32 | 11111111111111111111111111111011 | FFFFFFFB | 4294967291 |
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.
| Calculator | You enter | It returns |
|---|---|---|
| [Binary Calculator](/technology/binary-calculator/) | first binary number, second binary number and operation | Result |
| [Hex Calculator](/technology/hex-calculator/) | first hex number, second hex number and operation | Result |
| [Hex to Text Converter](/technology/hex-to-text/) | hex bytes | Text |
| [Binary to Text Converter](/technology/binary-to-text/) | binary bytes | Text |
| [Number Base Converter](/technology/base-calculator/) | number, from base and to base | Result |
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.
Related calculators
- 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.
- Binary to Text Converter — Decode groups of 8 bits as UTF-8 text.
- Number Base Converter — Convert a number between bases 2 and 36.
- Download Time Calculator — Time to download a file at a given speed.
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.