0
\$\begingroup\$

We were learning about full adder and half adder circuits and how overflow might occur in them. My professor told that for a full adder of n bits the range is [-2^(n-1) , 2^(n-1)-1]. What I don't get is why is -2^(n) also in the list. For example if I am using 4 bits and then I add -4 + -4 = -8 which in 2's complement form is 11101, and then on performing the usual operation of discarding carry and checking the signed bit the answer comes out to be 0.

\$\endgroup\$
2

3 Answers 3

2
\$\begingroup\$

Welcome to Electrical Engineering SE.

[Two's complement:] for a full adder of n bits the range is [-2^(n-1) , 2^(n-1)-1]. What I don't get is why is -2^(n) also in the list.

\$ -2^n \$ isn't in the range you (correctly) quoted. Were you thinking of \$ -2^{n-1} \$ ?

I trust that you are happy that with \$ n \$ bits we can represent \$ 2^n \$ numbers. We can divide that range into 2 equal halves each representing \$ 2^{n-1} \$ numbers.

For negative numbers we can use one half of the range to represent numbers from \$ -1 \$ to \$ -2^{n-1} \$.

However for non-negative numbers we need to use one of the bit patterns from the other half of the range to represent \$ 0 \$ so our maximum positive number is reduced by \$ 1 \$ compared to the magnitude of the most negative number. So the non-negative range runs from \$ 0 \$ to \$ 2^{n-1}-1 \$.

Hence the total range is \$ [ 2^{n-1} , 2^{n-1}-1 ] \$ as you quoted. In two's complement representation the most negative number will always be even and will have a magnitude (absolute value) one more than the most positive number, which will always be odd (for \$ n > 1 \$).

\$\endgroup\$
1
\$\begingroup\$

-8 which in 2's complement form is 11101

Nope, -8 is just 1000 in 2s complement form, and also the smallest signed number that fits in 4 bits.

\$\endgroup\$
1
\$\begingroup\$

digital logic is normaly build just to handle unsigned integers but you can just map ones complement and two's complement to these integers and if you interpret the unsigned integers as twos complement numbers it turns out that the result is correct in the limits of availible bits.

enter image description here

-4 = 1100

       1100
     + 1100
carry 11000
       ----
       1000

1000 = -8
\$\endgroup\$
2
  • \$\begingroup\$ I like the right figure, but the left one is misleading. Overflow should also be shown in the lower half. \$\endgroup\$
    – Janka
    Commented Sep 8, 2020 at 15:37
  • \$\begingroup\$ @Janka you are right to the point, that its the same technical issue... I just did paste n copy from my studies formula collection. So we used both words just to make clear at which position of the circle the overflow happened \$\endgroup\$
    – schnedan
    Commented Sep 8, 2020 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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