slide04 numsys ops part2

Upload: -

Post on 06-Apr-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Slide04 NumSys Ops Part2

    1/25

    Number Systems &

    Operations

    Part II

  • 8/3/2019 Slide04 NumSys Ops Part2

    2/25

    Arithmetic Operations with

    Signed NumbersBecause the 2s complement form for representing

    signed numbers is the most widely used in computer

    systems. Well limit to 2s complement arithmetic on:

    Addition

    Subtraction Multiplication

    Division

  • 8/3/2019 Slide04 NumSys Ops Part2

    3/25

    Addition

    4 cases that can occur when 2 signed numbers are

    added:

    Both numbers positive

    Positive number with magnitude larger than negative

    number

    Negative number with magnitude larger than positivenumber

    Both numbers negative

  • 8/3/2019 Slide04 NumSys Ops Part2

    4/25

    Addition

    Both numbers positive:

    ex: 00000111! ! 7! ! ! ! !! ! !

    00001011! !

    11

    The sum is positive and is therefore in true

    (uncomplemented) binary.

  • 8/3/2019 Slide04 NumSys Ops Part2

    5/25

    Addition

    Positive number with magnitude larger than negative

    number:

    ex: 00001111! ! 15! ! ! ! !! ! 1 00001001!! 9

    The final carry bit is discarded. The sum is positive and is

    therefore in true (uncomplemented) binary.

    Discardcarry

  • 8/3/2019 Slide04 NumSys Ops Part2

    6/25

    Addition

    Negative number with magnitude larger than positive

    number:

    ex: 00010000! ! 16! ! ! !! ! ! ! 11111000! ! -8

    The sum is negative and therefore in 2s complement

    form.

  • 8/3/2019 Slide04 NumSys Ops Part2

    7/25

    Addition

    Both numbers negative:

    ex: 11111011!! -5! ! ! !!! ! 1 11110010! ! -14

    The final carry bit is discarded. The sum is negative and

    therefore in 2s complement form.

    Discardcarry

  • 8/3/2019 Slide04 NumSys Ops Part2

    8/25

    Addition

    Remark: The negative numbers are stored in 2s complement

    form so, as you can see, the addition process is very

    simple:Add the two numbers and discard any

    carry bit.

  • 8/3/2019 Slide04 NumSys Ops Part2

    9/25

    Addition

    Overflow condition:

    When two numbers are added andthe number of bits required to

    represent the sum exceeds the

    number of bits in the two numbers,

    an overflowresults as indicated by

    an incorrect sign bit.

    An overflow can occur only when

    both numbers are + or -.

    ex: 01111101 125

    10110111 183

    Magnitudeincorrect

    Sign

    incorrect

  • 8/3/2019 Slide04 NumSys Ops Part2

    10/25

    AdditionNumbers are added two at a time:

    Computer add strings of numbers two numbers at a

    time.

    ex: add the signed numbers: 01000100, 00011011, 00001110, and00010010

    ! ! ! 68!! 01000100! ! ! !! !Add 1st two numbers! ! ! 95!! 01011111! 1st sum! ! ! !! !Add 3rd number! ! ! 109!! 01101101! 2nd sum! ! ! !! !Add 4th number! ! ! 127!! 01111111! Final sum

  • 8/3/2019 Slide04 NumSys Ops Part2

    11/25

    Subtraction

    Subtraction is of addition.

    Subtraction is addition with the sign of the subtrahendchanged.

    The result of a subtraction is called the difference.

    The sign of a positive or negative binary is changed bytaking its 2s complement.

  • 8/3/2019 Slide04 NumSys Ops Part2

    12/25

    Subtraction

    Since subtraction is simply an addition with the sign of

    the subtrahend changed, the process is stated asfollows:

    To subtract two signed numbers, take the 2s

    complement of the subtrahend and add.

    .

  • 8/3/2019 Slide04 NumSys Ops Part2

    13/25

    Subtraction

    ex: Perform each of the following subtraction of the signed numbers:

    (a) 00001000 00000011!! (b) 00001100 11110111!

    (c) 11100111 00010011!!

    (d) 10001000 - 11100010

    ! (a) 00001000! 8! ! (b) 00001100! 12!! ! ! ! ! !! 100000101! 5! ! 00010101! 21! (c) 11100111! -25! ! (d) 10001000 -120! ! ! ! ! 111010100! -44! ! 10100110 -90

  • 8/3/2019 Slide04 NumSys Ops Part2

    14/25

    Hexadecimal and Octal

    Numbers

  • 8/3/2019 Slide04 NumSys Ops Part2

    15/25

    Hexadecimal Numbers

    We will call it for short as hex.

    It has 16 characters. Digits 0-9 and letters A-F.

    It used primarily as a compact way of displaying or writingbinary numbers since it is very easy to convert betweenbin and hex.

    Hex is widely used in computer and microprocessorapplications.

  • 8/3/2019 Slide04 NumSys Ops Part2

    16/25

    Hexadecimal Numbers

    Decimal Binary Hexadecimal

    0 0000 0

    1 0001 1

    2 0010 2

    3 0011 3

    4 0100 4

    5 0101 5

    6 0110 6

    7 0111 7

    8 1000 8

    9 1001 910 1010 A

    11 1011 B

    12 1100 C

    13 1101 D

    14 1110 E

    15 1111 F

  • 8/3/2019 Slide04 NumSys Ops Part2

    17/25

    Hexadecimal Numbers

    If you see h mixing in numbers (in the context of

    computer systems), please note that its most likely that

    the numbers are hexadecimal numbers. (Be careful. h isnot one of A-F using in hex).

    For example

    16h = 000101102

    0Dh = 000011012

  • 8/3/2019 Slide04 NumSys Ops Part2

    18/25

    Hexadecimal Numbers

    Bin-to-Hex Conversion

    Simply break the binary number into 4-bit groups,

    starting at the right-most bit and replace each 4-bitgroup with the equivalent hex symbol.

    (a) 1100101001010111! ! (b) 111111000101101001 1100101001010111!! 00111111000101101001

    ! C A 5 7! ! 3 F 1 6 9! ! = CA5716! ! ! ! = 3F16916

  • 8/3/2019 Slide04 NumSys Ops Part2

    19/25

    Hexadecimal Numbers

    Hex-to-Bin Conversion

    Reverse the process (of bin-to-hex) and replace eachhex symbol with the appropriate four bits.

    ex: Determine the binary numbers for the following hex numbers:

    (a) 10A4h! (b) CF8Eh!! (c) 9742h1 0 A 4! C F 8 E! 9 7 4 2

    0001000010100100! 1100111110001110 1001011101000010

  • 8/3/2019 Slide04 NumSys Ops Part2

    20/25

    Hexadecimal Numbers

    Hex-to-Dec Conversion

    2 methods:

    Hex-to-Bin first and then Bin-to-Dec.

    Multiply the decimal values of each hex digits by its

    weight and then take the sum of these products.

  • 8/3/2019 Slide04 NumSys Ops Part2

    21/25

    Hexadecimal Numbers

    Hex-to-Dec Conversion

    Hex-to-Bin first and then Bin-to-Dec

    ex: Convert the following hex numbers to decimal:

    (a) 1Ch

    1Ch = 00011100 = 16+8+4 = 2810

    (b) A85h

    A85h = 101010000101 = 2048+512+128+4+1 = 269310

  • 8/3/2019 Slide04 NumSys Ops Part2

    22/25

    Hexadecimal Numbers

    Hex-to-Dec Conversion

    Multiply the decimal values of each hex digits by itsweight and then take the sum of these products.

    ex: Convert the following hex numbers to decimal:

    (a) E5h

    E5h = (Ex16)+(5x1) = (14x16)+5 = 224+5 = 22910

    (b) B2F8h

    B2F8h = (Bx4096)+(2x256)+(Fx16)+(8x1)

    = (11x4096)+(2x256)+(15x16)+(8x1)

    ! ! = 45,056+512+240+8 = 45,81610

  • 8/3/2019 Slide04 NumSys Ops Part2

    23/25

    Hexadecimal Numbers

    Dec-to-Hex conversion

    Repeated division of a dec number by 16

    ex: Convert the dec number 650 to hex

    650/16 = 40.625 0.625x16 = 10 = A

    40/16 = 2.5 0.5x16 = 8 = 8

    2/16 = 0.125 0.125x16 = 2 = 2Stop when whole

    number quotient isZERO.

    MSD

    LSD

    Hence 65010= 28Ah

  • 8/3/2019 Slide04 NumSys Ops Part2

    24/25

    Octal Numbers

    Like the hex, the oct provides a convenient wayto express binary numbers and codes. (btw, itsnot as commonly used as hex).

    8 digits: 0-7 0,1,2,3,4,5,6,7,10,11,12,13,14,15,16,17,20,

    Operations we learn about hexso far work the

    same way on oct just mark this: Hex = 4 binary bits

    Oct = 3 binary bits

    Now, lets crack the following exercises

  • 8/3/2019 Slide04 NumSys Ops Part2

    25/25

    Octal NumbersBin-to-Oct Conversion

    (a) 110101!! ! (b) 101111001(c) 100110011010 !(d) 11010000100

    Oct-to-Bin Conversion(a) 13

    8(b) 25

    8(c) 140

    8(d) 7526

    8

    Oct-to-Dec Conversion

    (a) 23748Dec-to-Oct Conversion

    (a) 35910