why does 2 s complement arithmetic work
Download
Skip this Video
Download Presentation
Why does 2’s complement arithmetic work?

Loading in 2 Seconds...

play fullscreen
1 / 10

Why does 2’s complement arithmetic work? - PowerPoint PPT Presentation


  • 71 Views
  • Uploaded on

COMP 40: Machine Structure and Assembly Language Programming (Fall 2013). Why does 2’s complement arithmetic work?. Noah Mendelsohn Tufts University Email: [email protected] Web: http://www.cs.tufts.edu/~noah. Goals for this presentation.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Why does 2’s complement arithmetic work?' - nicki


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
why does 2 s complement arithmetic work

COMP 40: Machine Structure and

Assembly Language Programming (Fall 2013)

Why does 2’s complement arithmetic work?

Noah Mendelsohn

Tufts UniversityEmail: [email protected]

Web: http://www.cs.tufts.edu/~noah

goals for this presentation
Goals for this presentation
  • Develop your intuitionabout why 2’s complement arithmetic works
the problem
The problem:
  • I get why:

2 is encoded as 00000010

  • I have no clue why:

-2 is encoded as 11111110

modular arithmetic
Modular arithmetic

What happens when this goes past 999999?

999999 + 1 = 0

So, what should 0-1 be?

unsigned modular arithmetic mod 256
Unsigned modular arithmetic – mod 256

00000000

11111111

255

0

00000001

1

254

11111110

00000010

2

192

11000000

128

10000000

signed m odular arithmetic mod 256
Signed modular arithmetic – mod 256

00000000

11111111

00000001

-1

0

1

11111110

-2

00000010

2

-64

11000000

-128

10000000

the 2s complement magic
The 2s complement magic

The hardware does the same thing, only the interpretatation is different!

ad