Public Group

# 2's complement problem?

This topic is 2783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i was recently told to do this

use only 4 bits and add +9 , -4 using 2's (these numbers are represented in 2's complement)?
is this even possible?
wouldn't u need 5 bits atleast??

##### Share on other sites
Quote:
 use only 4 bits and add +9 , -4 using 2's

Would help a bit if you clarified exactly what the heck you're saying.

Depending on if you're using signed or unsigned, 4 bits may be enough. Unsigned gives you between [0,15], signed gives you [-8,7]

##### Share on other sites
Adding and subtracting will overflow with 4 bits, but the overflow is...nondestructive? in this case, and you'll get the correct result.

2's complement form is a way to convert a number to/from a bitwise representation.

For example if I give you the following bits without any information about what form they're in, they're just bits:

1001

That could be 9 in unsigned form or -7 in 2's complement form.

-4 in 2's complement 4-bit form is 1100.

  1001+ 1100------  0101 with carry

so the result is that you have 5 as the result, and your carry flag has been set.

##### Share on other sites
but both numbers should be represented in 2's complement, your -9 is not using this format with only 4 bits

##### Share on other sites
Using 4 bits and 2's complement you can only represent integers in the range [-8,8), so your question about adding +9 and -4 doesn't make much sense.

In a more mathematically-sound way of looking at things, 4-bit numbers are actually congruency classes of the integers modulo 16. In that sense, +9 and -7 are the same number (1001), and so are -4 and +12 (1100). You can add them together and the result is 9+12 = 21 = 5 (0101).

##### Share on other sites
The only way I can think of is like so using 5 bits. But maybe the sign extension doesn't count?

01001(9)
11100(-4)
---------
00101(5)

1. 1
Rutin
19
2. 2
3. 3
JoeJ
15
4. 4
5. 5

• 22
• 19
• 11
• 13
• 17
• ### Forum Statistics

• Total Topics
631698
• Total Posts
3001768
×