How it’s calculated
Computers store signed whole numbers in two's complement. With N bits, the leftmost bit has the negative place value −2ᴺ⁻¹ and every other bit its usual positive value, so a leading 1 means the number is negative. There is only one zero, and the range is lopsided: one more negative number than positive.
Example: −13 in 8 bits. 13 is 0000 1101; flipping the bits gives 1111 0010; adding 1 gives 1111 0011 (hex F3). Reading it back: −128 + 64 + 32 + 16 + 2 + 1 = −13. Read as an unsigned number the same bits are 243, and 243 − 256 = −13.
Frequently asked questions
Why does 1111 1111 mean −1?
In 8-bit two's complement the leftmost bit is worth −128 and the rest add up to 127, so the total is −1. All ones is −1 at every width.
Why is the range −128 to 127 and not −127 to 127?
Zero takes one of the non-negative patterns, so there are 128 negative patterns (leftmost bit 1) and only 127 positive ones. 1000 0000 is −128 and has no positive partner.
How do I sign-extend to more bits?
Copy the leftmost bit into the new positions. −5 is 1011 in 4 bits and 1111 1011 in 8 bits; both mean −5. A positive number gets zeros on the left.
What happens if a number does not fit?
It overflows: 200 cannot be stored as a signed 8-bit number (the maximum is 127). The calculator says so instead of wrapping around; choose a wider bit width.
Embed this calculator
Add this free calculator to your own website. Copy the code below into your page’s HTML:
Need this calculator branded, changed or built around your own prices?See custom business solutions →
Sources
- Dive Into Systems, §4.3 Signed Binary Integers (two's complement, flip the bits and add one, −13 = 0b11110011) — Dive Into Systems (Matthews, Newhall & Webb; West Point and Swarthmore College), free online textbook
Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.
Added · Last updated · How we check our calculators
Spotted a mistake or missing option? Report a problem· Suggest a calculator