1. Signed Number Representation ➕➖
Computers need an efficient way to represent both positive and negative numbers. While sign-and-magnitude is intuitive for humans, it's inefficient for hardware. Therefore, computers primarily use **1's Complement** and **2's Complement** systems, with 2's Complement being the standard for modern arithmetic.
Range & Representation Explorer
Select the number of bits to see the representable range and check if a number fits within that range.
1's Complement Range
[ -15 to 15 ]
2's Complement Range
[ -16 to 15 ]
Convert 2's Complement Binary to Decimal
2. Sign Extension
When performing arithmetic with numbers of different bit-widths (e.g., adding an 8-bit number to a 16-bit number), the smaller number must be extended to match the larger width without changing its value. This is done through **sign extension**, where the sign bit (the most significant bit) of the smaller number is copied to fill the new, higher-order bits.
Sign Extension Visualizer
Original 8-bit (2's Complement):
Sign-Extended Result:
3. Multiplication & Division by Shifting 🚀
For powers of 2, multiplication and division can be performed using very fast bit-shifting operations. A left shift multiplies a number by 2 for each position shifted, while a right shift divides it by 2. For signed numbers in 2's complement, a special **Arithmetic Right Shift** is needed for division to preserve the sign bit.
Bit-Shift Arithmetic Calculator
Original 8-bit (2's Complement):
Multiplication (Left Shift)
Division (Arithmetic Right Shift)
4. Multiplication of Signed Numbers (Booth's Algorithm)
Multiplying signed numbers in 2's complement form can be complex. **Booth's Algorithm** is an efficient method that works for both positive and negative numbers. It examines the current and previous bits of the multiplier to decide whether to add the multiplicand, subtract it, or do nothing, followed by an arithmetic right shift.
Interactive Booth's Algorithm
Multiply -5 (M = 1011) by -6 (Q = 1010) using 4 bits.
Cycle | A | Q | Q-1 | Action |
---|
5. Division (Restoring Division)
Division is a more complex operation, typically performed through a sequence of shifts and subtractions. The **Restoring Division** algorithm is a straightforward method for unsigned integers. It involves shifting the combined Remainder (A) and Quotient (Q) registers left, subtracting the Divisor (M), and then restoring the Remainder if the result is negative.
Interactive Restoring Division
Divide 13 (Dividend Q = 01101) by 5 (Divisor M = 00101) using 5 bits.
Step | A | Q | Action |
---|