So I'm creating a little binary subtractor, using two's complement, but I've run into a problem. I have inverted the second input and added 1 through the first carry in, and everything works fine with positive numbers but when i want negative outputs, the sign bit changes, but i get a different answer. But if i take the twos complement of the output i get the correct answer. It works but there's something wrong with my method right?
If it works without Two's Complement than just don't use it. The only reason I see it being necessary is if you wanted to do more with your machine and it was absolutely required to do it.
If it works without Two's Complement than just don't use it. The only reason I see it being necessary is if you wanted to do more with your machine and it was absolutely required to do it.
Well what I'm saying is that the positive numbers work right when i use two's complement, but im doing something wrong when its negative, and taking the inverted output+1 gives me the actual negative output with the sign bit, so i can get it to work, but people do it without this and i wanna know what i did wrong.
You have to put the sum through a second set of adders. Each sum goes into either the A or B input, with the Carry in activated. That will give you your correct result. You can control this by looking at the most significant bit while you're doing subtraction. If the MSB is activated, you have a negative number. Let me know if I made sense. I have an adder on CraftedMovie that I can take screens of for you if you need it.
Rollback Post to RevisionRollBack
"It has become appallingly obvious that our technology has exceeded our humanity." -Albert Einstein
http://www.youtube.com/user/xpew75
Well what I'm saying is that the positive numbers work right when i use two's complement, but im doing something wrong when its negative, and taking the inverted output+1 gives me the actual negative output with the sign bit, so i can get it to work, but people do it without this and i wanna know what i did wrong.
http://www.youtube.com/user/xpew75