Please enable JavaScript.
Coggle requires JavaScript to display documents.
Arithmetic on Signed 8-bit Integers - Coggle Diagram
Arithmetic on Signed 8-bit Integers
Arithmetic on Signed 8-bit Integers (2's Complement)
Given Numbers
A = +45
B = −23
Representation: 8-bit 2's complement
1. Binary Conversion
Step 1: Convert +45 to Binary
Decimal 45 = 00101101
+45 = 00101101
Step 2: Convert −23 to Binary
First convert 23 to binary:
23 = 00010111
Take 1's complement:
00010111
↓
11101000
Add 1 (2's complement):
11101000
+00000001
11101001
Therefore,
−23 = 11101001
2. Addition: (+45) + (−23)
Binary Addition
00101101 (+45)
11101001 (−23)
1 00010110
Ignore the carry out of the MSB (leftmost carry).
Final Result:
00010110
Convert to decimal:
00010110 = 22
Answer
45 + (−23) = 22
Overflow Check
Overflow occurs only when:
Positive + Positive → Negative
Negative + Negative → Positive
Here,
One number is positive.
One number is negative.
Therefore,
No Overflow.
3. Subtraction: (+45) − (−23)
Subtracting a negative number means adding its positive value.
45−(−23)\=45+2345 - (-23) = 45 + 2345−(−23)\=45+23
Binary of +23
00010111
Now add:
00101101 (+45)
+00010111 (+23)
01000100
Convert to decimal:
01000100 = 68
Answer
45 − (−23) = 68
Overflow Check
Operands:
Positive
Positive
Result:
Positive (68)
Since the result is still within the 8-bit signed range (-128 to +127),
No Overflow.
4. Sign Bit Alignment
In 8-bit signed numbers:
MSB (Most Significant Bit) is the sign bit.
0 = Positive
1 = Negative
Decimal
Binary
Sign Bit
+45
00101101
0
−23
11101001
1
Both operands already occupy 8 bits, so no extra sign extension is needed.
5. Processor Overflow Detection
A processor detects overflow by checking the carry into and carry out of the sign bit.
Rule 1
Overflow occurs if:
Carry into MSB ≠ Carry out of MSB
Rule 2 (Common Rule)
Positive + Positive → Negative = Overflow
Negative + Negative → Positive = Overflow
Positive + Negative = Never Overflow
Addition Case
+45 + (−23)
Signs are different.
No Overflow.
Subtraction Case
+45 − (−23)
= +45 + +23
Both operands are positive.
Result = +68 (still positive).
No Overflow.
6. Final Results
Operation
Binary Result
Decimal Result
Overflow
+45 + (−23)
00010110
22
No
+45 − (−23)
01000100
68
No
Conclusion
+45 is represented as 00101101.
−23 is represented as 11101001 using 2's complement.
Addition produces 00010110 (22) with no overflow because the operands have different signs.
Subtraction is performed by adding +23, giving 01000100 (68) with no overflow since the result is within the valid 8-bit signed range.
The processor detects overflow by comparing the carry into and carry out of the sign bit or by checking whether adding two numbers with the same sign produces a result with the opposite sign.