1 / 18

Chapter # 5: Arithmetic Circuits 5.1 -- Number Systems

Chapter # 5: Arithmetic Circuits 5.1 -- Number Systems. Binary Number Representation Sign & Magnitude, Ones Complement, Twos Complement Binary Addition Full Adder Revisted. Chapter Overview. Representation of positive numbers same in most systems

hogan
Download Presentation

Chapter # 5: Arithmetic Circuits 5.1 -- Number Systems

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter # 5: Arithmetic Circuits5.1 -- Number Systems

  2. Binary Number Representation Sign & Magnitude, Ones Complement, Twos Complement Binary Addition Full Adder Revisted Chapter Overview

  3. Representation of positive numbers same in most systems Major differences are in how negative numbers are represented Three major schemes: sign and magnitude ones complement twos complement Assumptions: we'll assume a 4 bit machine word 16 different values can be represented roughly half will represent positive numbers and zero, remainder will represent negative numbers Number Systems Representation of Negative Numbers

  4. Number Systems 1. Sign and Magnitude Representation Most significant bit is sign: 0 = positive (or zero), 1 = negative Three low order bits is the magnitude: 0 (000) thru 7 (111) Number range for n bits = +/-2 -1 ==>  2 - 1 =  7 for 3 bits 2 Representations for 0: 0000, 1000 n-1 3

  5. Number Systems 2. Ones Complement N is positive number, then N is its negative 1's complement n 4 N = (2 - 1) - N 2 = 10000 -1 = 00001 1111 -7 = 0111 1000 Example: 1's complement of 7 = -7 in 1's comp. Shortcut method: simply compute bit wise complement 0111 -> 1000

  6. All negative numbers have a 1 in their sign bit. Still two representations of 0! This causes some problems Number Systems Ones Complement

  7. Only one representation for 0 One more negative number than positive number Negative numbers have a 1 in the highest order bit ==> sign bit Number Representations 3. Twos Complement like 1's comp except shifted one position clockwise

  8. Number Systems Twos Complement Numbers n N* = 2 - N 4 2 = 10000 7 = 0111 1001 = repr. of -7 sub Example: Twos complement of 7 4 2 = 10000 -7 = 1001 0111 = repr. of 7 Example: Twos complement of -7 sub Shortcut method: Twos complement = bitwise complement + 1 (+7) 0111 -> 1000 + 1 -> 1001 (representation of -7) (-7) 1001 -> 0110 + 1 -> 0111 (representation of 7)

  9. Number Representations Addition and Subtraction of Numbers 1. Sign and Magnitude 4 + 3 7 0100 0011 0111 -4 + (-3) -7 1100 1011 1111 result sign bit is the same as the operands' sign when signs differ, operation is subtract, sign of result depends on sign of number with the larger magnitude 4 - 3 1 0100 1011 0001 -4 + 3 -1 1100 0011 1001 Adder and subtractor required to implement addition and subtraction.

  10. Number Representations Sign and Magnitude Cumbersome addition/subtraction Must compare magnitudes to determine sign of result Ex. 0111 + 1010 7 + (-2)=> One number is positive and one number is negative. +7 > (-2)=> Subtract 7-2 111 - 010 101 assign sign of largest number ===> 0101

  11. Number Systems Addition and Subtraction of Numbers 2. Ones Complement Calculations (+4) Same Signs 0100 ---> 4 + 3 7 0100 0011 0111 -4 + (-3) -7 1011 1100 10111 1 1000 0011 --> (+3) If result yields a carryout, add it to the lsb (least significant bit) End around carry (+4) Different Signs 0100 1100 10000 1 0001 4 - 3 1 0100 ---> -4 + 3 -1 1011 0011 1110 0011 --> (+3) End around carry

  12. Number Systems Addition and Subtraction of Numbers Subtraction implemented by addition & 1's complement. A-B = A + (-B) Some complexities in addition due to two zeros.

  13. Number Systems Addition and Subtraction of Binary Numbers Ones Complement Calculations Why does end-around carry work? Its equivalent to subtracting 2 and adding 1 n n n M - N = M + N = M + (2 - 1 - N) = (M - N) + 2 - 1 (M > N) n n -M + (-N) = M + N = (2 - M - 1) + (2 - N - 1) = 2 + [2 - 1 - (M + N)] - 1 n-1 M + N < 2 n n n after end around carry: - (2 - 1 ) n = 2 - 1 - (M + N) this is the correct form for representing -(M + N) in 1's comp!

  14. Number Systems Addition and Subtraction of Binary Numbers Same Sign carry-in 3. Twos Complement Calculations 1 4 + 3 7 0100 0011 0111 -4 + (-3) -7 1100 1101 11001 If carry-in to sign = carry-out then ignore carry if carry-in differs from carry-out then overflow. overflow -- arithmetic operation results in a number outside the range of those that can be represented. carry-out Different Sign 4 - 3 1 0100 1101 10001 -4 + 3 -1 1100 0011 1111 Simpler addition scheme makes twos complement the most common choice for integer number systems within digital systems

  15. Number Systems Addition and Subtraction of Binary Numbers Twos Complement Calculations Why can the carry-out be ignored? -M + N when N > M: n n M* + N = (2 - M) + N = 2 + (N - M) n Ignoring carry-out is just like subtracting 2 n-1 -M + -N where N + M < or = 2 n n -M + (-N) = M* + N* = (2 - M) + (2 - N) = 2 - (M + N) + 2 n n After ignoring the carry, this is just the right twos compl. representation for -(M + N)!

  16. Number Systems Overflow Conditions Add two positive numbers and result is a negative number or two negative numbers and result is a positive number -1 -1 +0 +0 -2 -2 1111 0000 +1 1111 0000 +1 1110 1110 0001 0001 -3 -3 +2 +2 1101 1101 0010 0010 -4 -4 1100 +3 1100 +3 0011 0011 -5 -5 1011 1011 0100 +4 0100 +4 1010 1010 -6 -6 0101 0101 +5 +5 1001 1001 0110 0110 -7 -7 +6 +6 1000 0111 1000 0111 -8 -8 +7 +7 -7 - 2 = +7 5 + 3 = -8

  17. Number Systems Overflow Conditions -- Two’s complement 0 1 1 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 0 1 0 0 1 1 1 1 0 1 0 1 1 1 5 3 -8 -7 -2 7 Overflow Overflow 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 0 0 0 5 2 7 -3 -5 -8 No overflow No overflow Overflow when carry in to sign does not equal carry out

  18. HW #10 -- Section 5.1

More Related