Representing Integers - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Representing Integers

Description:

All data must be stored as binary numbers. Positive integers have direct conversion ... Sum is trickier... Hint: when is the output 1? 7. Subtraction ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 16
Provided by: atkinso
Category:

less

Transcript and Presenter's Notes

Title: Representing Integers


1
Representing Integers
  • Positive integers
  • Adding binary numbers
  • Turning addition into subtraction
  • Twos complement
  • Example

2
Positive Integers
  • All data must be stored as binary numbers
  • Positive integers have direct conversion
  • 000 0 001 1 010 2 011 3
  • 100 4 101 5 110 6 111 7

3
Adding Decimal Integers
  • Perform addition on each column and record
    carrys
  • 456
  • 27
  • -------
  • 483

4
Adding Binary Integers
  • Perform addition on each column and record
    carrys
  • 111
  • 10
  • -------
  • 1001

5
A Truth Table for Addition
  • For each bit, there are two inputs (a, b) and two
    outputs (sum, carry)

6
Logic Gates for Addition
  • Basic logic gates are AND, OR, NOT
  • Carry is easy ? just an AND gate
  • Sum is trickier
  • Hint when is the output 1?

7
Subtraction
  • Perform subtraction on each space and record
    borrows
  • 456
  • - 27
  • -------
  • 429

8
An Easier Way
  • Subtraction is addition of a negative number
  • Rather than develop a new mechanism, we can
    recycle the previous mechanism
  • Reduce hardware complexity!

9
Negative Numbers
  • How do we usually represent a negative number?
  • Should a computer use this representation?

10
From Addition to Subtraction
  • 456 27 456 (-27)
  • 456
  • -27
  • -------
  • 429

11
A Different Representation
12
Using Twos Complement
  • 7 2 7 (-2)
  • 0111 (7)
  • 1110 (-2)
  • --------
  • 0101 (5)

13
Creating a Negative Number
  • What is 2?
  • 0010
  • What is the inverse of 2?
  • 1101
  • What did we want for 2?

14
Example
  • Using twos complement, addition, and an 8-bit
    representation, subtract 13 from 7

15
Summary
  • All data is stored as binary numbers
  • Internal and external representations do not have
    to be the same
  • Twos complement representation simplifies
    computer hardware
Write a Comment
User Comments (0)
About PowerShow.com