Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.

Similar presentations


Presentation on theme: "Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers."— Presentation transcript:

1 Lecture No. 4 Computer Logic Design

2 Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers and most digital systems

3 Sign-magnitude Representation Signed Binary Numbers –Most significant bit represents sign –MSB of 0 => positive number; MSB of 1 => negative number Problem –Representing 0 (e.g. +0 0000 and -0 1000) –Not computation friendly Sign Magnitude Form 1101-5 0010+2 1111-7!!

4 1’s & 2’s Complement Form Representation 1’s complement form –Derived by inverting all bits 2’s complement form –Derived by adding 1 to 1’s complement Binary number 00001101(13 d ) 1’s complement11110010(-13 d ) + 1 2’s complement11110011(-13 d )

5 Signed Number Example +92  01011100 In sign-magnitude form -92  11011100 In 1’s complement form -92  10100011 In 2’s complement form -92  10100100 Shortcut to form 2’s complement: Do not flip any bits to the right of and including the first “1” Flip all bits to the left of the first “1”

6 Decimal Value of Signed Numbers Sign-magnitude form –Sum the weights in all magnitude bit positions where there are 1s –Sign is determined by examination of the sign bit 110111- (16 + 4 + 2 + 1)-23 d 1’s Complement form –Assign a negative value to the weight of the sign bit –Sum the weights in all bit positions, where there are 1s –Add 1 to the result 100110(-32 +4 +2) +1-25 d 2’s Complement form –Assign a negative value to the weight of sign bit –Sum the weights in all bit positions, where there are 1s 110111(-32 +16 + 4 +2 + 1)-9 d

7 Decimal Value of Signed Numbers Alternate Method 1’s Complement form –Convert Negative Number to Positive –Attach –ve sign bit 100110 => 011001(-ve) 25 d 2’s Complement form –Convert Negative Number to Positive –Attach –ve sign bit 110111 => 001001(-ve) 9 d

8 Range of Binary Numbers Unsigned Numbers Total combos for “n” binary bits = 2 n Range: 0 … + (2 n -1) Sign Magnitude Form - (2 n-1 -1) … + (2 n-1 -1) 2’s Complement Form - (2 n-1 ) … + (2 n-1 -1)

9 Important Info about 2’s Comp #s 2’s complement representation is for negative numbers only Before representing 2’s complement numbers, ensure it can fit in the given range of bits - e.g for n-bit numbers range is: - (2 n-1 ) … + (2 n-1 -1) Overflow occurs only when MSB changes contrary to result expectation, otherwise discard carry.

10 Arithmetic Operations w/ Signed Numbers Addition –straightforward as we shall see Subtraction –Change sign of Subtrahend and Add Multiplication –Shift and add each partial product term Division –Repetitively subtract Divisor from Dividend – but subtraction is again addition

11 Addition with 2’s Complement 1011 -50101+5 0010+21110 -2 1101 -3 0011+3 1011-50101+5 1110-2 0010+2 1 1001-7 0111+7  Discard any final carry bit

12 Subtraction with 2’s Complement 0101100189 01011001 89 - 0010110145+ 11010011-45 ??????????1 00101100 44  Discard any final carry bit

13 Overflows Overflow conditions –Indicated by an incorrect sign bit –There is a carry into the sign bit which produces an overflow condition –Can occur only when both numbers are positive or both numbers are negative 01111101(+125 d ) 00111010 (+58 d ) 10110111(+183 d )

14 Add the signed numbers: 01000100 00011011 00001110 10010010

15 Floating Point Numbers To represent very large/very small integers Numbers that have both integer and fractional parts A Floating point number consists of two parts plus a sign –Exponent: Number of places that the binary point is to be moved (power of 2) –Mantissa; represents the magnitude of the number A format is defined by ANSI/IEEE 754 –Single precision, double precision and extended precision

16 Floating Point Numbers Single Precision Floating Point Binary Number +1101100000111 2 +1.101100000111 x 2 12 (Normalized form) S = 0 Biased Exponent = 10001011 (127 + 12 = 139) Mantissa = 10110000011100000000000 (hidden 1) Mantissa 1000101110110000011100000000000 0 Biased ExpS

17 Floating Point Numbers +1.101 x 2 5 -1.01011 x 2 -126 0 ∞ 10000100 10100000000000000000000 0 00000001 01011000000000000000000 1 00000000 00000000000000000000000 0 11111111 00000000000000000000000 0

18 Need for Hexadecimal Number System Long binary numbers are difficult to read and write; easy to transpose or drop a bit Most digital systems process binary data in groups that are multiples of four bits -> easy to convert Base 16 number system Ten digits and six alphabetic characters –0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

19 Hexadecimal Number System Counting in Hexadecimal –Once we get to F, we start over with another column and continue DecimalBinaryHexadecimalDecimalBinaryHexadecimal 000000810008 100011910019 200102101010A 300113111011B 401004121100C 501015131101D 601106141110E 701117151111F

20 Hexadecimal Number System Counting in Hexadecimal DecimalHexa- Decimal Hexa- Decimal Hexa- Decimal 161024183220 171125193321 1812261A3422 1913271B3523 2014281C3624 2115291D3725 2216301E3826 2317311F3927

21 Hexadecimal Number System Binary to Hexadecimal Conversion –Starting from the LSB, replace each 4-bit group with the equivalent hexadecimal symbol 1101 0110 1011 1001 0110 D 6 B9 6 Hexadecimal to binary conversion –Replace each hexadecimal digit with appropriate four bits F D 1 3 1111 1101 0001 0011

22 Hexadecimal Number System Hexadecimal-to-Decimal Conversion –Sum-of-Weights Method CA02 h = (C x 16 3 ) + (A x 16 2 ) + (0 x 16 1 ) + (2 x 16 0 ) = (12 x 16 3 ) + (10 x 16 2 ) + (0 x 16 1 ) + (2 x 16 0 ) = (12 x 4096) + (10 x 256) + (0 x 16) + (2 x 1) = 49152 + 2560 + 0 + 2 = 51714

23 Hexadecimal Number System Decimal to Hexadecimal Conversion –Repeated Division-by-16 method Number÷ 16x 16Hex Remainder 85953.68750.6875B h (or 11 d ) 533.31250.31255h5h 30.1875 3h3h  Result: 35B h STOP when 0 reached

24 Hexadecimal Number System Hexadecimal Addition –In any given column, think of two hexadecimal digits in terms of their decimal values –Example Carry 1 2 A C 66+5=11 d B h + 9 2 B 5C+B=23 d 17 h B D7 BA+2+1=13 d D h 2+9=11 d B h

25 Hexadecimal Number System Hexadecimal Subtraction –Example Borrow 111 92B521-6=15 d F h - 2AC626-C=14 d E h 67EF17-A=7 d 7 h 8-2=6 d 6 h


Download ppt "Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers."

Similar presentations


Ads by Google