0
$\begingroup$

What I know 1=negative,0=positive Example 1. 27-13=14 Example 2. -39+92=53 For example 1. 27 to binary is 11011 13 to binary is 1101

So 1101 change to two complement will be 0011. So for the calculation 11011+0011 gives me 11110. However the correct answer should be 1110, which is binary of 14. Why there is an extra 1 at the leftmost part?

For example 2. -39 to binary is 100111 to two complement will be 011001 92 to binary is 1011100 So add them up will give me 1110101, which is not the binary of 53 (110101), again because of the extra 1 . Can someone explain to me why?

$\endgroup$

1 Answer 1

2
$\begingroup$

Two's complement is always done with a specific bit width in mind, and you use modular arithmetic within that width. Basically, you should ignore that leading 1, it's the output carry and should be modulo'd away.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.