Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Digital Logic Design Lecture 2 More Number Systems/Complements.

Similar presentations


Presentation on theme: "1 Digital Logic Design Lecture 2 More Number Systems/Complements."— Presentation transcript:

1 1 Digital Logic Design Lecture 2 More Number Systems/Complements

2 2 Overview °Hexadecimal numbers Related to binary and octal numbers °Conversion between hexadecimal, octal and binary °Value ranges of numbers °Representing positive and negative numbers °Creating the complement of a number Make a positive number negative (and vice versa) °Why binary?

3 3 Understanding Binary Numbers °Binary numbers are made of binary digits (bits): 0 and 1 °How many items does an binary number represent? (1011) 2 = 1x2 3 + 0x2 2 + 1x2 1 + 1x2 0 = (11) 10 °What about fractions? (110.10) 2 = 1x2 2 + 1x2 1 + 0x2 0 + 1x2 -1 + 0x2 -2 °Groups of eight bits are called a byte (11001001) 2 °Groups of four bits are called a nibble. (1101) 2

4 4 Understanding Hexadecimal Numbers °Hexadecimal numbers are made of 16 digits: (0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F) °How many items does an hex number represent? (3A9F) 16 = 3x16 3 + 10x16 2 + 9x16 1 + 15x16 0 = 14999 10 °What about fractions? (2D3.5) 16 = 2x16 2 + 13x16 1 + 3x16 0 + 5x16 -1 = 723.3125 10 °Note that each hexadecimal digit can be represented with four bits. (1110) 2 = (E) 16 °Groups of four bits are called a nibble. (1110) 2

5 5 Putting It All Together °Binary, octal, and hexadecimal similar °Easy to build circuits to operate on these representations °Possible to convert between the three formats

6 6 Converting Between Base 16 and Base 2 °Conversion is easy!  Determine 4-bit value for each hex digit °Note that there are 2 4 = 16 different values of four bits °Easier to read and write in hexadecimal. °Representations are equivalent! 3A9F 16 = 0011 1010 1001 1111 2 3A9F

7 7 Converting Between Base 16 and Base 8 1.Convert from Base 16 to Base 2 2.Regroup bits into groups of three starting from right 3.Ignore leading zeros 4.Each group of three bits forms an octal digit. 35237 8 = 011 101 010 011 111 2 52373 3A9F 16 = 0011 1010 1001 1111 2 3A9F

8 8

9 9 Decimal 2 Binary

10 10 Octal Numbers: [Base 8],[ 0,1,3,4,5,6,7] Octal to Decimal Conversion: Example:- [2374] 8 = [ ? ] 10 =4×8 0 +7×8 1 +3×8 2 +2×8 3 =[1276] 10 Number systems () Number systems (Octal Numbers) °Octal number has base 8 °Each digit is a number from 0 to 7 °Each digit represents 3 binary bits °Was used in early computing, but was replaced by hexadecimal

11 11 Decimal to Octal Conversion: The Division: [359] 10 = [ ? ] 8 By using the division system: 7 4 5 74 5 Reminder Number systems () Number systems (Octal Numbers) Quotient

12 12 Binary to Octal Conversion: Example:- [110101] 2 = [ ? ] 8 Here we will take 3 bits and convert it from binary to decimal by using the decimal to binary truth table: BinaryDecimal 1106 1015 1 1 01 0 1= (65) 8 { 65 { Number systems () Number systems (Octal Numbers)

13 13 Octal to Binary Conversion: Example:- [13] 8 = [ ? ] 2 Here we will convert each decimal digit from decimal to binary (3 bits) using the decimal to binary truth table: BinaryDecimal 1001 3011 (13) 8 = (001011) 2 Number systems () Number systems (Octal Numbers)

14 14 Radix Based Conversion (Example) °Convert 1234 decimal into octal Radix 8Answer 2322 8 Divide by radix 8 81234 81542 8192 23

15 15 Octals Converting to decimal from octal: –Evaluate the power series Example 2 0 7 8 0 21 0*8 1 2*8 2 + 7*8 0 + = 135 10

16 16 Hexadecimal °Hexadecimal is used to simplify dealing with large binary values: Base-16, or Hexadecimal, has 16 characters: 0-9, A-F Represent a 4-bit binary value: 0000 2 (0) to 1111 2 (F) Easier than using ones and zeros for large binary values Commonly used in computer applications °Examples: 1100 2 = 12 10 = C 16 1010 0110 1100 0010 2 = A6 C2 16 Hex values can be followed by an “H” to indicate base-16. Example: A6 C2 H

17 17 Hex Values in Computers

18 18 Decimal to Hexadecimal DecimalHex 00 11 22 33 44 55 66 77 88 99 10A 11B 12C 13D 14E 15F

19 19 Conversion Binary to Hexadecimal 1010110000010110 1010 = 101100 = 120001 = 10110 = 6 AC16

20 20 Radix Based Conversion (Example) °Convert 1234 decimal into hexadecimal Radix 16Answer 4D2 16 Divide by radix 16 161234 16772 4D

21 21 Hexadecimals – Base 16 Converting to decimal from hex: –Evaluate the power series Example 2 E A 16 0 21 14*16 1 2*16 2 + 10*16 0 + = 746 10

22 22 Octal to Hex Conversion  To convert between the Octal and Hexadecimal numbering systems  Convert from one system to binary first  Then convert from binary to the new numbering system

23 23 Hex to Octal Conversion Ex : Convert E8A 16 to octal First convert the hex to binary: 1110 1000 1010 2 111010001010and re-group by 3 bits (starting on the right) Then convert the binary to octal: 7 2 1 2 So E8A 16 = 7212 8

24 24 Octal to Hex Conversion Ex : Convert 752 8 to hex First convert the octal to binary: 111 101 010 2 re-group by 4 bits 0001 1110 1010 (add leading zeros) Then convert the binary to hex: 1 E A So 752 8 = 1EA 16

25 25 Octal to Hexadecimal Hexadecimal DecimalOctal Binary

26 26 Octal to Hexadecimal °Technique Use binary as an intermediary

27 27 Example 1076 8 = ? 16 1 0 7 6 001 000 111 110 2 3 E 1076 8 = 23E 16

28 28 Hexadecimal to Octal Hexadecimal DecimalOctal Binary

29 29 Hexadecimal to Octal °Technique Use binary as an intermediary

30 30 Example 1F0C 16 = ? 8 1 F 0 C 0001 1111 0000 1100 1 7 4 1 4 1F0C 16 = 17414 8

31 31 Example: Hex → Octal Example: °Convert the hexadecimal number 5A H into its octal equivalent. 5A H = 132 8 5A 16 1 16 0 161 80+10 = 90 10 Solution: °First convert the hexadecimal number into its decimal equivalent, then convert the decimal number into its octal equivalent.

32 32 Fractions (Example)

33 33 Fractions (Example)

34 34 Radix Based Conversion (Example) °Convert 0.6875 decimal into binary Radix 2 Answer0.1011 2 FractionRadixTotal (Fraction x Radix)IntegerFraction 0.687521.37510.375 20.750 21.510.5 2110 Multiply by radix 2

35 35 FractionRadix Total (Fraction x Radix)IntegerFraction 0.513168.20880.208 163.32830.328 165.24850.248 163.96830.968 Radix Based Conversion (Example) °Convert 0.513 10 to base 16 (up to 4 fractional point) Radix 16 Answer0.8353 16 Multiply by radix 16

36 36

37 37 How To Represent Signed Numbers Plus and minus sign used for decimal numbers: 25 (or +25), -16, etc..For computers, desirable to represent everything as bits. Three types of signed binary number representations: signed magnitude, 1’s complement, 2’s complement. In each case: left-most bit indicates sign: positive (0) or negative (1). Consider signed magnitude: 00001100 2 = 12 10 Sign bitMagnitude 10001100 2 = -12 10 Sign bitMagnitude

38 38 Complement °It has already been studied that °subtracting one number from another is the same as making one number negative and just adding them. °We know how to create negative numbers in the binary number system. °How to perform 2’s complement process. °How the 2’s complement process can be use to add (and subtract) binary numbers. °Digital electronics requires frequent addition and subtraction of numbers. You know how to design an adder, but what about a subtracter? °A subtracter is not needed with the 2’s complement process. The 2’s complement process allows you to easily convert a positive number into its negative equivalent. °Since subtracting one number from another is the same as making one number negative and adding, the need for a subtracter circuit has been eliminated.

39 39 3-Digit Decimal A bicycle odometer with only three digits is an example of a fixed-length decimal number system. The problem is that without a negative sign, you cannot tell a +998 from a -2 (also a 998). Did you ride forward for 998 miles or backward for 2 miles? Note: Car odometers do not work this way. 999 998 997 001 000 999 998 002 001 forward (+) backward (-)

40 40 Negative Decimal How do we represent negative numbers in this 3-digit decimal number system without using a sign?  Cut the number system in half.  Use 001 – 499 to indicate positive numbers.  Use 500 – 999 to indicate negative numbers.  Notice that 000 is not positive or negative. 499 498 497 001 000 999 998 501 500 pos(+) neg(-) +499 +498 +497 +001 000 -002 -499 -500

41 41 3-Digit Decimal (Examples) 3 + 2 5 003 + 002 005 (-5) + 2 (-3) 995 + 002 997 6 + (-3) 3 (-2) + (-3) (-5) 006 + 997 1  003 Disregard Overflow 998 + 997 1  995 Disregard Overflow It Works!

42 42 Complex Problem °The previous examples demonstrate that this process works, but how do we easily convert a number into its negative equivalent? °In the examples, converting the negative numbers into the 3-digit decimal number system was fairly easy. To convert the (-3), you simply counted backward from 1000 (i.e., 999, 998, 997). °This process is not as easy for large numbers (e.g., -214 is 786). How did we determine this? °To convert a large negative number, you can use the 10’s Complement Process.

43 43 Complement The 10’s Complement process uses base-10 (decimal) numbers. Later, when we’re working with base-2 (binary) numbers, you will see that the 2’s Complement process works in the same way. First, complement all of the digits in a number. A digit’s complement is the number you add to the digit to make it equal to the largest digit in the base (i.e., 9 for decimal). The complement of 0 is 9, 1 is 8, 2 is 7, etc. Second, add 1. Without this step, our number system would have two zeroes (+0 & -0), which no number system has.

44 44 10’s Complement Examples -003 +1  996 997 -214 +1  785 Example #1 Example #2 Complement DigitsAdd 1Complement DigitsAdd 1 786

45 45 One’s Complement Representation The one’s complement of a binary number involves inverting all bits. 1’s comp of 00110011 is 11001100 1’s comp of 10101010 is 01010101 For an n bit number N the 1’s complement is (2 n -1) – N. Called diminished radix complement by Mano since 1’s complement for base (radix 2). To find negative of 1’s complement number take the 1’s complement. 00001100 2 = 12 10 Sign bitMagnitude 11110011 2 = -12 10 Sign bitMagnitude

46 46 Two’s Complement Representation The two’s complement of a binary number involves inverting all bits and adding 1. 2’s comp of 00110011 is 11001101 2’s comp of 10101010 is 01010110 For an n bit number N the 2’s complement is (2 n -1) – N + 1. Called radix complement by Mano since 2’s complement for base (radix 2). To find negative of 2’s complement number take the 2’s complement. 00001100 2 = 12 10 Sign bitMagnitude 11110100 2 = -12 10 Sign bitMagnitude

47 47 Two’s Complement Shortcuts °Algorithm 1 – Simply complement each bit and then add 1 to the result. Finding the 2’s complement of (01100101) 2 and of its 2’s complement… N = 01100101[N] = 10011011 10011010 01100100 + 1 + 1 --------------- 10011011 01100101 °Algorithm 2 – Starting with the least significant bit, copy all of the bits up to and including the first 1 bit and then complementing the remaining bits. N = 0 1 1 0 0 1 0 1 [N] = 1 0 0 1 1 0 1 1

48 48 Finite Number Representation °Machines that use 2’s complement arithmetic can represent integers in the range -2 n-1 <= N <= 2 n-1 -1 where n is the number of bits available for representing N. Note that 2 n-1 -1 = (011..11) 2 and –2 n-1 = (100..00) 2 oFor 2’s complement more negative numbers than positive. oFor 1’s complement two representations for zero. oFor an n bit number in base (radix) z there are z n different unsigned values. (0, 1, …z n-1 )

49 49 1’s Complement Addition °Using 1’s complement numbers, adding numbers is easy. °For example, suppose we wish to add +(1100) 2 and +(0001) 2. °Let’s compute (12) 10 + (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 1’s comp. (1) 10 = +(0001) 2 = 00001 2 in 1’s comp. 0 1 1 0 0 +0 0 0 0 1 -------------- 0 0 1 1 0 1 0 -------------- 0 1 1 0 1 Add carry Final Result Step 1: Add binary numbers Step 2: Add carry to low-order bit Add

50 50 1’s Complement Subtraction °Using 1’s complement numbers, subtracting numbers is also easy. °For example, suppose we wish to subtract +(0001) 2 from +(1100) 2. °Let’s compute (12) 10 - (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 1’s comp. (-1) 10 = -(0001) 2 = 11110 2 in 1’s comp. 0 1 1 0 0 -0 0 0 0 1 -------------- 0 1 1 0 0 +1 1 1 1 0 -------------- 1 0 1 0 1 0 1 -------------- 0 1 0 1 1 Add carry Final Result Step 1: Take 1’s complement of 2 nd operand Step 2: Add binary numbers Step 3: Add carry to low order bit 1’s comp Add

51 51 2’s Complement Addition °Using 2’s complement numbers, adding numbers is easy. °For example, suppose we wish to add +(1100) 2 and +(0001) 2. °Let’s compute (12) 10 + (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 2’s comp. (1) 10 = +(0001) 2 = 00001 2 in 2’s comp. 0 1 1 0 0 +0 0 0 0 1 -------------- 0 0 1 1 0 1 Final Result Step 1: Add binary numbers Step 2: Ignore carry bit Add Ignore

52 52 2’s Complement Subtraction °Using 2’s complement numbers, follow steps for subtraction °For example, suppose we wish to subtract +(0001) 2 from +(1100) 2. °Let’s compute (12) 10 - (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 2’s comp. (-1) 10 = -(0001) 2 = 11111 2 in 2’s comp. 0 1 1 0 0 -0 0 0 0 1 -------------- 0 1 1 0 0 +1 1 1 1 1 -------------- 1 0 1 0 1 1 Final Result Step 1: Take 2’s complement of 2 nd operand Step 2: Add binary numbers Step 3: Ignore carry bit 2’s comp Add Ignore Carry

53 53 2’s Complement Subtraction: Example #2 °Let’s compute (13) 10 – (5) 10. (13) 10 = +(1101) 2 = (01101) 2 (-5) 10 = -(0101) 2 = (11011) 2 °Adding these two 5-bit codes… °Discarding the carry bit, the sign bit is seen to be zero, indicating a correct result. Indeed, (01000) 2 = +(1000) 2 = +(8) 10. 0 1 1 0 1 +1 1 0 1 1 -------------- 10 1 0 0 0 carry

54 54 2’s Complement Subtraction: Example #3 °Let’s compute (5) 10 – (12) 10. (-12) 10 = -(1100) 2 = (10100) 2 (5) 10 = +(0101) 2 = (00101) 2 °Adding these two 5-bit codes… °Here, there is no carry bit and the sign bit is 1. This indicates a negative result, which is what we expect. (11001) 2 = -(7) 10. 0 0 1 0 1 +1 0 1 0 0 -------------- 1 1 0 0 1

55 55 1’s Complement

56 56 2’s Complement 1s complement with negative numbers shifted one position clockwise Only one representation for 0 One more negative number than positive number High-order bit can act as sign bit

57 57 Overflow °Overflow conditions °Add two positive numbers to get a negative number °Add two negative numbers to get a positive number

58 58 Two’s Complement Number System 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 0 1 2 3 4 5 6 7 -8-8 -7-7 -6-6 -5-5 -4-4 -3-3 -2-2 -1  -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 

59 59 Summary °Binary numbers can also be represented in octal and hexadecimal °Easy to convert between binary, octal, and hexadecimal °Signed numbers represented in signed magnitude, 1’s complement, and 2’s complement °2’s complement most important (only 1 representation for zero). °Important to understand treatment of sign bit for 1’s and 2’s complement.


Download ppt "1 Digital Logic Design Lecture 2 More Number Systems/Complements."

Similar presentations


Ads by Google