image This is an image of a binary subtractor for unsigned numbers. Some times the output of binary subtraction is not correct and needs to be complemented to give the correct answer, how can I find out when those times are?


closed as off-topic by Marcus Müller, evildemonic, Voltage Spike, Finbarr, Dave Tweed May 21 at 18:06

  • This question does not appear to be about electronics design within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ what about trying out all inputs? Alternatively, you could just write down the boolean equation that models this circuit, and try to figure out from that, by comparing to the boolean equation describing subtraction. (I'd recommend the latter) \$\endgroup\$ – Marcus Müller May 19 at 16:35
  • 5
    \$\begingroup\$ I'm voting to close this question as off-topic because this is a homework / learning material question without any own attempt. \$\endgroup\$ – Marcus Müller May 19 at 16:36
  • 1
    \$\begingroup\$ write out the equations: [ N + (the complemented M) = N - M + error ], and determine how to detect the error. \$\endgroup\$ – analogsystemsrf May 19 at 17:04

In general, you observe the carry into the most-significant bit and the carry out of the most-significant bit. If you try a few values you will observe a pattern in those two values when the result of the subtraction is incorrect.

If you don't have access to the carries then you will need to brute-force compare the magnitudes of the numbers. When computing \$A-B\$ the result will be incorrect if \$B > A\$

  • \$\begingroup\$ Or if you want to do things "the hard way" you could say, given C athe result of (A - B): if B is negative, C must be greater than A, OR if B is positive, C must be less than A. Any solution that violates those expectations must be inaccurate. I haven't checked if that is a necessary or sufficient logic for detecting overflow, and it's obviously not the most efficient way of detecting it, but it might work ;-). Another way to reason about @Elliot's answer is "does the result come out the same if you have another bit of precision to work with and you sign-extend the arguments". \$\endgroup\$ – vicatcu May 19 at 18:05
  • \$\begingroup\$ @vicatcu Agreed, but the OP stated that the subtractor was for unsigned values so I didn't mention the possibility of B being negative. \$\endgroup\$ – Elliot Alderson May 19 at 18:39

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