ToolSphere

Two's Complement Calculator

Computer science

Convert decimal and signed binary in 4, 8, 16 or 32 bits. Compare signed formats and check two's complement overflow with step-by-step work shown.

8-bit two's complement

11110011

Decimal: -13

Range: -128 to 127

Conversion work

  1. Write the magnitude: 00001101.
  2. Invert every magnitude bit: 11110010.
  3. Add 1: 11110011.

Two's complement addition and subtraction

Arithmetic always uses two's complement at the selected width. Enter decimal operands from -128 to 127.

Stored result: -96 · Signed overflow

10100000

Exact mathematical result: 160

Sign-bit carry in: 1; carry out: 0. XOR = 1.

  1. Encode A: 01100100; B: 00111100.
  2. Add A and B, starting with carry 0.
  3. Work from bit 0 (least significant) toward the sign bit. Keep only 8 result bits.
  4. Compare the carry into and out of the sign bit. Different carries mean signed overflow; equal carries mean no signed overflow.
Bit-by-bit carry trace (B column uses B)
BitABCarry inSumCarry out
000000
100000
211001
301101
401101
511111
610101
700110

On this browser only

Give feedback

Did this tool help?

Tell us what worked, what didn’t, or what you’d like next.

Opens Google Forms in a new tab with this tool’s name filled in. No sign-in or email required. Feedback is optional.

How to use Two's Complement Calculator

  1. 1Choose a bit width and signed format. The loaded example converts decimal −13 at 8 bits.
  2. 2Select a conversion direction and enter a decimal integer or an exact-width binary word.
  3. 3Read the conversion steps and the range above the fields.
  4. 4Enter decimal A and B in the separate two's complement arithmetic section to inspect addition or subtraction and the carry trace.

About Two's Complement Calculator

Signed binary with work shown

Use this two's complement calculator for Digital Logic and Computer Organization homework. Convert decimal integers to fixed-width signed binary, or decode a binary word back to decimal. Choose two's complement, one's complement, or sign-magnitude to see how the same value is represented under different conventions. A loaded example appears before the controls, followed by the conversion steps. The separate arithmetic section shows addition or subtraction, its stored result, and a carry trace.

Choose the width before interpreting a bit pattern. A binary word does not carry its own type information: its meaning depends on both the number of bits and the representation. This calculator supports whole integers only. It does not interpret fractional fixed-point numbers, floating-point fields, hexadecimal input, or processor-specific status registers. Calculations run locally in your browser, so you can experiment without submitting homework inputs to a server.

Choose a representation and range

Two's complement assigns a negative weight to the most significant bit. For width n, its range is −2^(n−1) through 2^(n−1) − 1. At 4 bits that means −8 through 7; at 8 bits it means −128 through 127. The 16-bit range is −32768 through 32767, and the 32-bit range is −2147483648 through 2147483647. There is one representation of zero and one extra negative value.

One's complement and sign-magnitude reserve patterns for both positive and negative zero. Their negative endpoint therefore has the same magnitude as the positive endpoint. At 8 bits their range is −127 through 127. The range displayed above the form follows your selected format and width. A decimal outside that range is rejected rather than silently wrapped or truncated. The arithmetic section always uses the two's complement range, independently of the conversion format.

Convert decimal to signed binary

Start by writing the absolute value in binary with enough leading zeros for the selected width. Positive values have the same encoding in all three formats. For a negative sign-magnitude value, set the sign bit and leave the remaining magnitude bits unchanged. For a negative one's complement value, invert every bit of the positive encoding. For a negative two's complement value, invert those bits and add one.

The loaded example converts −13 at 8 bits. Its magnitude is 00001101. Inverting all bits gives 11110010, the one's complement encoding. Adding one gives 11110011, the two's complement encoding. Sign-magnitude instead gives 10001101. These values were generated by this tool's calculation library. Changing the format keeps your decimal input so you can compare the encodings directly. Entering −0 preserves negative zero where the chosen representation supports it.

Decode a binary word

Select signed binary to decimal and enter exactly the chosen number of bits, including leading zeros. Spaces inside the word and prefixes are rejected. A leading zero means an ordinary nonnegative binary value. With a leading one, two's complement decoding subtracts 2^n from the unsigned value. For the loaded word 11110011, the unsigned reading is 243; subtracting 256 gives −13.

One's complement decoding inverts a negative word to recover its magnitude, then applies a negative sign. Sign-magnitude removes the sign bit before reading the magnitude. The page explicitly labels negative zero rather than hiding it. Switching direction transfers a valid current result into the input, allowing you to check the round trip without retyping a long word.

Check addition and subtraction overflow

Enter decimal A and B in the arithmetic section. Addition uses their two's complement words directly. Subtraction uses A + NOT(B) + 1: invert B and set the initial carry to one. The table works from the least significant bit upward, recording both input bits, incoming carry, sum bit, and outgoing carry at each position. Its final row is the sign-bit operation.

For the loaded 8-bit addition, 100 + 60 has exact result 160. The stored word is 10100000, which decodes to −96. The carry into the sign bit is 1 and the carry out is 0, so their XOR is 1 and signed overflow is reported. For −100 − 60, the exact result is −160 while the stored word 01100000 represents 96. Its sign-bit carries are 0 and 1, again indicating overflow.

Distinguish carry from signed overflow

A final carry alone does not prove signed overflow. At 8 bits, −1 + 1 produces zero with both sign-bit carries equal to 1; their XOR is zero. Compare the exact mathematical answer with the allowed range as a second check. When overflow occurs, the displayed stored answer describes the retained bits, not a valid representation of the exact answer at that width.

The carry rule here applies to the two's complement adder, including subtraction implemented with the initial carry. This page does not perform one's complement end-around-carry arithmetic or sign-magnitude arithmetic. For ordinary unsigned arithmetic and bitwise AND, OR, or XOR, use the binary calculator. To study the gate operations used inside an adder, continue with the logic gate simulator.

Guides and tutorials

Frequently asked questions

What is two's complement?

It is a fixed-width signed integer encoding whose most significant bit has negative weight. Negative values can be formed by inverting the positive magnitude word and adding one.

How do I convert decimal to two's complement?

Choose a width, enter a whole decimal integer and select Two's complement. The result shows the padded binary word and the inversion/add-one steps for negative inputs.

Can I convert signed binary back to decimal?

Yes. Choose Signed binary to decimal and enter exactly the selected number of binary digits. Choose the representation used by your assignment before interpreting the word.

What is the 8-bit two's complement range?

It is −128 through 127. One's complement and sign-magnitude at the same width represent −127 through 127 and have two zero patterns.

How does the carry rule detect overflow?

Signed overflow occurs when the carry into the sign bit differs from the carry out. The calculator shows both values and their XOR, with each bit's carry in the trace table.

How does subtraction work?

The arithmetic section computes A + NOT(B) + 1 at the selected width. The B column uses the inverted B word and the initial carry is one. This also handles the most-negative operand without separately negating it.

Does a carry out always mean signed overflow?

No. Carry out concerns unsigned arithmetic. For signed two's complement arithmetic compare both sign-bit carries, or check whether the exact result fits the signed range.

Why do some formats show negative zero?

One's complement and sign-magnitude have distinct positive and negative zero patterns. Binary decoding preserves that distinction, and decimal −0 can be encoded in those formats. Two's complement has one zero.

Does arithmetic follow the conversion format?

No. Conversion supports all three formats, but addition and subtraction always use two's complement. One's complement end-around carry and sign-magnitude arithmetic are outside this tool's scope.

Are out-of-range inputs wrapped?

Decimal conversion and arithmetic operands outside their permitted ranges are rejected. Valid arithmetic operands can produce overflow; then the page shows both the exact answer and the retained fixed-width result.

Have a suggestion for Two's Complement Calculator?Share your feedback ↗