Understanding the Effects of 2's Complement on Arithmetic Operations

Click For Summary

Discussion Overview

The discussion revolves around the effects of 2's complement representation on arithmetic operations, specifically addressing discrepancies in expected results during addition of negative and positive binary numbers. The scope includes technical explanations and clarifications regarding the conversion process between binary and decimal representations in 2's complement.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant questions why the results of certain arithmetic operations using 2's complement differ from expected values, citing specific examples.
  • Another participant corrects the binary representations of -64 and -16, asserting that -64 is 11000000 and -16 is 11110000 in 2's complement.
  • A different participant provides a calculation for 11000000, interpreting it as -62, and questions their understanding of the conversion process.
  • Another participant suggests that the previous calculation may involve an error in the bit inversion process, indicating that one should add one after inverting the bits.
  • One participant agrees with a previous comment and outlines the algorithm for converting negative numbers into 2's complement, detailing the steps for both conversion and interpretation of the binary values.
  • A later reply acknowledges a misunderstanding regarding the inversion process, indicating that the last bit should not be left unchanged during calculations.

Areas of Agreement / Disagreement

Participants express differing views on the correct application of the 2's complement conversion process, with some providing corrections and clarifications while others question their own understanding. No consensus is reached on the initial arithmetic discrepancies.

Contextual Notes

Some limitations include potential misunderstandings in the bit inversion process and the handling of the last bit during conversions, which remain unresolved in the discussion.

geft
Messages
144
Reaction score
0
Why is it that when using 2's complement, the result of arithmetic operations differ by two?

11011001 (-39) +
11100111 (-25) =
11000000 (which is -62 in 2's complement, even though it's supposed to be -64)

00110011 (51) +
11101110 (-16) =
00100001 (33, but it's supposed to be 35)
 
Physics news on Phys.org
Some errors:

-64 is 11000000 in 2's complement.

-16 is 11110000 in 2's complement.
 
64 is 11000000 in 2's complement.

Am I doing it wrong?
11000000
=> 00111110
= 2^1 + 2^2 + 2^3 + 2^4 + 2^5 = 62
=> -62

16 is 11110000 in 2's complement.

11110000
=> 00001110
= 2^1 + 2^2 + 2^3 = 14
=> -14
 
geft said:
Am I doing it wrong?
11000000
=> 00111110
Looks like you're subtracting one after inverting the bits? I believe you always add one, so it should be
00111111 + 1 = 01000000

and
11110000
=> 00001110
00001111 + 1 = 00010000
 
Agree with eumyang.

The algorithm for dealing with negative numbers (positives are easy--do nothing) is this :

To convert, say -64 into 8-bit 2's complement:
1) Take the 8-bit binary of the positive part (64): 0100 0000
2) Since the original value is negative, complement the result from 1) and add 1: 1011 1111 + 1 = 1100 0000


To find the decimal given the 8-bit 2's complement value, say for 1100 0000:
1) Note that the MSB is a 1 and therefore your result will be a negative number.
2) Complement the original value: 1100 0000 => 0011 1111
3) Add 1: 0011 1111 + 1 = 0100 0000 (which is binary 64)
4) Apply the negative sign from part 1) to the result from part 3) "-" : 64 = -64
 
I see where I was wrong... I thought I didn't need to change the last bit in any way, so when inverting I always leave the last bit alone. Thanks!
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 2 ·
Replies
2
Views
17K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
3
Views
4K
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K