1
\$\begingroup\$

In my lab, we successfully built a 4-bit binary parallel adder and were able to display the results of some tests on the 7 segment display.

But our TA asked us to try something: subtract 1-9, and we got 7. Why is that?

\$\endgroup\$
6
  • 2
    \$\begingroup\$ how did you do the subtraction? How are we supposed to know what's wrong if you don't explain that? \$\endgroup\$ Oct 2, 2017 at 20:54
  • \$\begingroup\$ I don't think anything is wrong at all: that was that TA's point. He said we were meant to get 7 on the display (even though 1-9 doesn't equal 7), but instead of telling us why, he suggested that we think about it on our own, and I haven't figured it out. \$\endgroup\$
    – gbm0102
    Oct 2, 2017 at 20:55
  • 1
    \$\begingroup\$ hint: integer wrapping \$\endgroup\$ Oct 2, 2017 at 20:56
  • \$\begingroup\$ was it 1 or 10h-9h=7h (hex) \$\endgroup\$ Oct 2, 2017 at 21:06
  • \$\begingroup\$ Wondering how, exactly, you implemented a subtraction with an adder... \$\endgroup\$
    – Trevor_G
    Oct 2, 2017 at 21:09

2 Answers 2

3
\$\begingroup\$

So basically whenever you do 1-9 in binary that looks like

00001 (1) - 01001(9)

however since most of the subtraction is done by twos complement it is actually

00001 + 10110 => 10111

Your display will only display the bottom four bits which are 0111, which is seven.

Cheers!

\$\endgroup\$
3
  • \$\begingroup\$ OP's system is 4-bit. Yours seems to be truncated 5-bit. Can you explain? \$\endgroup\$
    – Transistor
    Oct 2, 2017 at 22:16
  • \$\begingroup\$ I think that would depend on how the adder was made and implemented, as well as how was the subtraction performed. From my labs we did "adder implementations" in some sort of HDL with fpga's tied to them that could be a case, I really don't know how you would subtract -9 in a 4 bit implementation \$\endgroup\$
    – zoder
    Oct 2, 2017 at 22:19
  • \$\begingroup\$ @Transistor if you do what he did, for 4 bits, still the system only shows 0111 which is still 7. \$\endgroup\$
    – parvin
    May 19, 2019 at 15:49
0
\$\begingroup\$

in binary:

1: 0001

Subtracting 9 times 1:

0000 (-1)
1111 (-2)
1110 (-3)
1101 (-4)
1100 (-5)
1011 (-6)
1010 (-7)
1001 (-8)
1000 (-9)

I would expect 1000, which is 8.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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