4electros
New Member
I was read at website the follows:
The subtraction operation always computes F-W, so be careful that you don't mean W-F. So if W contains 3 and x contains 10, performing a subtraction will result in 7. When subtracting, the C bit is a borrow flag. If the result was negative, then C will equal 0. If the C flag is 1, no borrow occurred. So computing 10-3 leaves C=1. But computing 3-10 will clear C. The result, in this case will be 0xF9 which is the two's compliment representation of -7.
To compute the two's compliment of a negative number, write the magnitude as a binary number. So for 7, we have 00000111. Then invert all the bits (11111000) and add 1 (11111001). You can easily reverse the process, so if I tell you the subtraction yields 0xF9, you can write it as binary (11111001), subtract 1 (11111000) and then invert the bits (00000111) to know that it means -7. When using this scheme the topmost bit acts like a sign bit.
The only problem is you can't readily tell a positive overflow from a negative number. For example, 0x70 is a positive number. Adding 0x70 to 0x70 yields 0xE0 which is correct, but is indistinguishable from a negative number. Therefore when performing signed arithmetic, you are limited to numbers from -128 to 127
but really don't understand the last section very well, could anyway advice me how to understand the idea in a good way , may be you can guide to other website which is designed to clear these things.
The subtraction operation always computes F-W, so be careful that you don't mean W-F. So if W contains 3 and x contains 10, performing a subtraction will result in 7. When subtracting, the C bit is a borrow flag. If the result was negative, then C will equal 0. If the C flag is 1, no borrow occurred. So computing 10-3 leaves C=1. But computing 3-10 will clear C. The result, in this case will be 0xF9 which is the two's compliment representation of -7.
To compute the two's compliment of a negative number, write the magnitude as a binary number. So for 7, we have 00000111. Then invert all the bits (11111000) and add 1 (11111001). You can easily reverse the process, so if I tell you the subtraction yields 0xF9, you can write it as binary (11111001), subtract 1 (11111000) and then invert the bits (00000111) to know that it means -7. When using this scheme the topmost bit acts like a sign bit.
The only problem is you can't readily tell a positive overflow from a negative number. For example, 0x70 is a positive number. Adding 0x70 to 0x70 yields 0xE0 which is correct, but is indistinguishable from a negative number. Therefore when performing signed arithmetic, you are limited to numbers from -128 to 127
but really don't understand the last section very well, could anyway advice me how to understand the idea in a good way , may be you can guide to other website which is designed to clear these things.