Computer Organization - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Computer Organization

Description:

Integers and Arithmetic Operations Terrence Mak * Counting to 9, oh no, 1 please Binary numbers (0, 1) are commonly used in computers as they are easily represented ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 17
Provided by: Michael3715
Category:

less

Transcript and Presenter's Notes

Title: Computer Organization


1
Computer Organization
  • Integers and Arithmetic Operations
  • Terrence Mak

2
Counting to 9, oh no, 1 please
  • Binary numbers (0, 1) are commonly used in
    computers as they are easily represented as
    on/off electrical signals
  • Other related radix systems are Octal
    Hexadecimal
  • Different number (representation) systems are
    used in computers
  • Let's assume n bits (binary digits) are used in
    the following discussions

3
Only 0 and 1 in a Sequence
  • Numbers are represented as binary vectors
  • B bn-1 bn-2 b1 b0
  • MSB Most Significant Bit bn-1 i.e. leftmost
    digit in a binary vector
  • LSB Least Significant Bit b0
  • i.e. rightmost digit in a binary vector

4
Representing Non-negative Numbers
  • Unsigned (non-negative) numbers are in range 0 to
    2n 1
  • Represented by Value(B) bn-1?2n-1 b1?21
    b0?20
  • if B is a binary vector representing an unsigned
    integer

5
Representing Signed Numbers
  • In written decimal system, a signed number is
    "usually" represented by a "dash" or "plus" sign
    and followed by the magnitude
  • e.g. 73, 215, 349
  • In binary system, we have several choices
  • Sign-and-magnitude
  • 1s complement
  • 2s complement

6
Representing Signed Numbers
  • Sign-and-magnitude
  • MSB determines sign, remaining unsigned bits
    represent magnitude
  • MSB 0 means "", 1 means ""
  • 1s complement
  • MSB determines sign
  • To change sign from unsigned to negative, invert
    all the bits
  • 2s complement (commonly used)
  • MSB determines sign
  • To change sign from unsigned to negative, invert
    all the bits and then add 1
  • This is equivalent to subtracting the positive
    number from 2n

7
Signed Number Systems
8
2s Complement
  • 2's complement numbers actually make sense since
    they follow normal modulo arithmetic except when
    they overflow
  • Range is 2(n1) to 2(n1) 1 e.g. 8 to 7
    for n 4

Overflow cut-off
for n 4, N 2n 24 16
9
1-bit Addition
10
n-bit Addition/ Subtraction
  • X Y
  • Use 1-bit addition propagating carry to the most
    significant bit
  • X Y
  • ? X ( Y)
  • Add X to the 2s complement of Y

11
4-bit Addition/ Subtractionof numbers
represented in 2s Complement
12
4-bit Addition/ Subtractionof numbers
represented in 2s Complement
13
Sign Extension
  • Given a 4-bit 2s complement number
  • Make it into an 8-bit 2's complement number
  • Positive number
  • add 0s to LHS
  • e.g. 0111 ? 00000111
  • Negative number
  • add 1s to LHS
  • e.g. 1010 ? 11111010
  • c.f. circle representation, i.e. extend the MSB

14
Overflow
  • In 2s complement arithmetic
  • Addition of opposite sign numbers never overflow
  • If the numbers are the same sign and the result
    is the opposite sign, overflow has occurred
  • e.g. 0111 0100 1011 5!
  • positive positive negative?!
  • In unsigned arithmetic
  • Carry out signals an overflow

15
Exercise
  • Using 4-bit 2s complement number system,
  • What is the binary for -2?
  • Calculate 23
  • Calculate -2-3
  • Calculate 55
  • Using 5-bit number system
  • What is the largest 2s complement number?
  • What is the smallest 2s complement number?
  • What is the largest unsigned number?
  • Convert 56 to unsigned binary
  • What is the decimal value of 10110101 in 2s
    complement?
  • What is the decimal value of unsigned number
    10110101?

16
Characters - 8-bit ASCII representation
Write a Comment
User Comments (0)
About PowerShow.com