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.