Understanding Signed Binary Arithmetic
Signed binary arithmetic lets computers store positive and negative integers using bits. The most common system is two’s complement because addition and subtraction use the same binary hardware. The highest bit acts as the sign indicator, yet its mathematical role depends on the selected representation. In an eight-bit two’s complement value, the range is −128 through 127. Sign-magnitude and one’s complement instead provide symmetrical positive and negative ranges, but both contain two representations of zero.
Two’s complement method
To form a negative two’s complement number, start with the positive binary magnitude. Invert every bit, then add one. For example, decimal 5 is 00000101 in eight bits. Inverting gives 11111010, and adding one gives 11111011. That final pattern represents −5. Sign extension preserves a signed value when increasing width. A negative two’s complement value therefore receives leading ones, while a positive value receives leading zeros.
Overflow and valid ranges
Fixed-width arithmetic cannot represent every possible result. Signed overflow occurs when the mathematical answer falls outside the chosen range. During two’s complement addition, adding two positive values must not produce a negative sign. Likewise, adding two negative values must not produce a positive sign. This calculator checks the exact mathematical result before wrapping it into the selected width. It therefore shows both the stored bit pattern and any overflow warning.
Choosing a representation
Two’s complement is best for modern computer arithmetic. One’s complement is useful for historical study and checksums. Sign-magnitude is intuitive because the leading bit directly indicates sign while remaining bits hold magnitude. Bitwise operations work on raw stored patterns, so their signed interpretation can differ from ordinary arithmetic. Changing the bit width also changes ranges and wrapped results. Comparing decimal, binary, and hexadecimal views helps reveal how identical bits can represent different numbers. These comparisons also make manual checking faster and clarify why identical bit patterns can produce different signed values.
Example signed values
| Decimal | 8-bit sign-magnitude | 8-bit one’s complement | 8-bit two’s complement |
|---|---|---|---|
| 5 | 00000101 | 00000101 | 00000101 |
| −5 | 10000101 | 11111010 | 11111011 |
| 12 | 00001100 | 00001100 | 00001100 |
| −12 | 10001100 | 11110011 | 11110100 |