I was doing an excercise when I realized:
a-2 = a-1-1 = a + (2'complement of 1) - 1
= a + (1's complement of 1 + 1) - 1
= a + 1's complement of 1
= a + 0
= a
So ultimately
a-2 = a
What did I do wrong here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Where you got it wrong is that
(2'complement of 1)is not(1's complement of 1 + 1).You need to be consistent in the way that you treat the operands, either they express two’s complement values or one complement’s values, it is not ok to mix both.
It is merely a convention, very much akin to the difference between signed and unsigned scalar types in various programming languages. You cannot mix signed and unsigned scalars in the same arithmetic operation and expect the result to be correct.
Specifically: (assuming 8 bits integer size, the argument is the same only the range of values allowed in either 1’s comp. or 2’s comp. differ).
In one’s complement convention,
1's complement of 1is11111110it represents the value 254 which is a value that cannot be represented in two’s complement convention (with 8 bit integers); the range of values you can have in two’s complement is -128 to +127.In your derivation your are therefore writing an operation that is invalid, let’s rewrite it using decimal values equivalencies: