Binary Addition:
sign | magnitude
0 - positive 1 - negative
operations considering sign (addition to subtraction)
first approach:
if signs are same
add directly
else
find the larger
subtract the smaller
fix the signsIs there a better approach?
2’s Complement
3-bit integers (wraps around) unique combinations first bit - sign, last two - magnitude 2 + 1 = 3
3 + -2 = 1
which got the correct answer if u consider first bit as the sign (we are)
Essentially addition but treating the sign bit like a normal bit
Converting signs
-
Flip digits e.g.
-
Add 1 e.g.