Public Group

# 2's complement question

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

## Recommended Posts

what does 2's complement mean exactly??

1.) 2's complement states that the numbering system were using will use this form for example
(0001)2 = (+1)10 (in 2's complement form)
(1111)2 = (-1)10 (in 2's complement form)

2.) does 2's complement just represent the negative value of a positive number? for example
(0001)2 = (+1)10 (in 2's unsigned form)<-- not 2's complement
(1111)2 = (-1)10 (in 2's complement form) <-- 2's complement

##### Share on other sites
Quote:
 Original post by nuclear123what does 2's complement mean exactly??

It means that the most significant bit is used to determine the number's signedness.

Quote:
 1.) 2's complement states that the numbering system were using will use this form for example (0001)2 = (+1)10 (in 2's complement form)(1111)2 = (-1)10 (in 2's complement form)

Yes. A helpful trick is to flip the bits and add one when you have a negative number, so:

11112 since the most significant bit is set, we know this number is negative
00002 flip the bits
Resulting in -110

Another example:
10012 MSB is set, this number is negative
01102 flip the bits
Resulting in -710

Quote:
 2.) does 2's complement just represent the negative value of a positive number? for example (0001)2 = (+1)10 (in 2's unsigned form)<-- not 2's complement(1111)2 = (-1)10 (in 2's complement form) <-- 2's complement

No. Remember that 2's complement is a way of interpreting a set of bits. The bits 11112 can be either -1 as a signed integer, or a 15 as an unsigned integer.

Take this inequality:

11112 > 01112 as unsigned integers evaluates to true since 15 > 7. However, as signed integers this evaluates to false since -1 < 7.

##### Share on other sites
Quote:
Original post by _fastcall
Quote:
 Original post by nuclear123what does 2's complement mean exactly??

It means that the most significant bit is used to determine the number's signedness.
Actually that's a totally inadequate description, as it could fit several signed number representations.

http://en.wikipedia.org/wiki/Two's_complement
http://en.wikipedia.org/wiki/Signed_number_representations

##### Share on other sites
One of the main reason why 2's compliment exist is their way to efficiently represents negative and positive numbers.

##### Share on other sites
AFAIK the main reason is the simplicity with which addition and subtraction can be done in hardware. Think on the famous
12 + 12 = 102
and carry bit propagation.

##### Share on other sites
Quote:
 Private message from nuclear123how does a computer need to determine wether the first value is negative or the second value?(0001)2 = (+1)10 (in 2's unsigned form)<-- unsigned(1111)2 = (-1)10 (in 2's complement form) <-- 2's complementhow does it know that 0001 is unsigned form and 1111 is 2's complement negative, and not 1111 unsigned?

Anyway: The computer doesn't know. A computer doesn't distinguish a type from a set of bits. The type is inferred by the operations performed on those bits. For example, there are two assembler instructions for multiplying two (Intel 8088) 16-bit registers: mul (unsigned integer multiply), and imul (signed integer multiply).

So, in a 4-bit architecture using 2's complement,
00012 will always be interpreted as +110 using mul and imul, and
11112 will be interpreted as +1510 when using mul, but will be interpreted as -110 when using imul.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 24
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633383
• Total Posts
3011591
• ### Who's Online (See full list)

There are no registered users currently online

×