Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.

Similar presentations


Presentation on theme: "Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1."— Presentation transcript:

1

2 Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1

3 Outline of Chapter 2 2.1 Decimal Numbers 2.2 Binary Numbers 2.3 Decimal to Binary Conversion 2.4 1’s and 2’s Compliment of Binary Numbers 2.5 Signed Numbers 2.6 Octal and Hexadecimal Numbers 2.7 BCD 2

4 2.1 Decimal numbers The decimal numbering system has 10 digits 0 through 9 A decimal number such as 7392 represents a quantity equal to 7 thousands plus 3 hundreds, plus 9 tens, plus 2 units. To be more exact, 7392 should be written as In general, the decimal numbering system has a base of 10 with each position weighted by a factor of 10 3

5 (Cont’d) In general, a number in base r contains r digits, 0, 1, 2,...,r-1, and is expressed as a power series in r with the general form 4

6 (Cont’d) in positional notation, only the coefficients and the radix point are written down: In general, the “. ” is called the radix point. is referred to as the most signifi-cant digit (msd) and as the least significant digit (lsd) of the number. Note that if m=0, the lsd is A -0 =A 0 It is customary to enclose the coefficients in parentheses and place a sub-script after the right parenthesis to indicate the base of the number 5

7 (Cont’d) The following illustrates a base 5 number with n=3 and n=1 and its conversion to decimal: Note that for all the numbers without the base designated, the arithmetic is performed with decimal numbers. Note also that the base 5 system uses only five digits, and, therefore, the values of the coefficients in a number can be only 0, 1, 2, 3, and 4. 6

8 2.2 Binary numbers The binary number system is a base 2 system with two digits: 0 and 1. A binary number such as 11010.11 is expressed with a string of 1s and 0s and, possibly, a binary point. Decimal equivalent of a binary number can be found by expanding the number into a power series with a base of 2. For example, 7

9 (Cont’d) As noted earlier, the digits in a binary number are called bits. When a bit is equal to 0, it does not contribute to the sum during the conversion. The decimal can be obtained by adding the numbers with powers of two corresponding to the bits that are equal to 1. For example, The first 24 numbers obtained from 2 to the power of n are listed in Table 2.1. 8

10 (Cont’d) In digital systems, we refer to 2 10 as K (kilo), 2 20 as M (mega), 2 30 as G (giga), and 2 40 as T (tera). Thus, and more conventional usage of K, M, G, and T as and, 10 3, 10 6, 10 9 respectively, sometimes applied as well. So caution is necessary in interpreting and using this notation. 9

11 (Cont’d) Table 2.1 Powers of Two 10

12 2.3 Decimal to binary conversion Two methods to convert decimal to binary:  1) Sum-of-weights method Determine the set of binary weights whose sum is equal to the decimal number and subtracts powers of two from the decimal number.  2) Repeated division-by-2 method (whole numbers) and repeated multiplication by 2 (Fractions) Repeatedly dividing the decimal number by 2 and retrieving the remainder. 11

13 1) Sum-of-weight method Binary weights 256 128 64 32 16 8 4 2 1 357 = 256 + 64 + 32 + 4 + 1 101100101 = 2 8 + 2 6 + 2 5 + 2 2 + 2 0 12

14 (Cont’d) for whole numbers 13

15 (Cont’d) for Fractions 14

16 2) Repeated division-by-2  Repeated division steps:  Divide the decimal number by 2  Write the remainder after each division until a quotient of zero is obtained.  The first remainder is the LSB and the last is the MSB Note, when done on a calculator, a fractional answer indicates a remainder of 1. 15

17 (Cont’d) Eg: 12 10 = X 2 45 10 = Y 2 ??? 16

18 Repeated multiplication of 2 (Fractions)  Step 1: multiply number by 2  Step 2: note the carry (1 or 0)  Step 3: repeat with new fraction  Stop when fraction part = 0 17

19 (Cont’d) 18

20 Generally: repeated division by 2 repeated multiplication by 2 19

21 2.4 Octal and Hexadecimal Octal Number System 20  The Octal Number System:  uses base 8  includes only the digits 0 through 7  The Octal system is based on the binary system with a 3-bit boundary

22 Binary − Octal Conversion OctalBinary 00 0 0 10 0 1 20 1 0 30 1 1 41 0 0 51 0 1 61 1 0 71 1 1 Example: ( 1 0 1 1 0. 0 1 ) 2 ( 2 6. 2 ) 8 Assume Zeros Works both ways (Binary to Octal & Octal to Binary) 21

23 Hexadecimal Number System (Cont’d)  Hexadecimal uses groups of 4 bits.  Base 16  16 possible symbols  0-9 and A-F 22

24 Binary − Hexadecimal Conversion HexBinary 00 0 10 0 0 1 20 0 1 0 30 0 1 1 40 1 0 0 50 1 60 1 1 0 70 1 1 1 81 0 0 0 91 0 0 1 A1 0 B1 0 1 1 C1 1 0 0 D1 1 0 1 E1 1 1 0 F1 1 Example: ( 1 0 1 1 0. 0 1 ) 2 ( 1 6. 4 ) 16 Assume Zeros Works both ways (Binary to Hex & Hex to Binary) 23

25 Octal − Hexadecimal Conversion Convert to Binary as an intermediate step Example: ( 0 1 0 1 1 0. 0 1 0 ) 2 ( 1 6. 4 ) 16 Assume Zeros Works both ways (Octal to Hex & Hex to Octal) ( 2 6. 2 ) 8 Assume Zeros 24

26 Con’t DecimalBinaryOctalHex 000000000 010001011 020010022 030011033 040100044 050101055 060110066 070111077 081000108 091001119 10101012A 11101113B 12110014C 13110115D 14111016E 15111117F Table 2.2 Numbers with Different bases 25

27 generally: Octal (Base 8) Evaluate Magnitude Decimal (Base 10) Binary (Base 2) Hexadecimal (Base 16) Evaluate Magnitude  Number Base Conversions 26

28 2.4 1’s and 2’s complement of binary numbers There are two types of complements for each base-r system: the radix complement and diminished radix complement. 1’s Complement (Diminished Radix Complement)  All ‘0’s become ‘1’s  All ‘1’s become ‘0’s Example (10110000) 2  (01001111) 2 If you add a number and its 1’s complement… 1 0 1 1 0 0 0 0 + 0 1 0 0 1 1 1 1 1 1 1 1 27 =>

29 2.4 1’s and 2’s Complements (Cont’d) 2’s Complement (Radix Complement) TTake 1’s complement then add 1 Example: Number: 1’s Comp.: 0 1 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0 1 0 0 1 1 1 1 + 1 1 0 1 1 0 0 0 0 00001010 28

30 Subtraction with Complements With the help of 2’s complement method we can easily subtract two binary numbers. The operation is carried out by means of the following steps: (i) At first, 2’s complement of the subtrahend is found. (ii) Then it is added to the minuend. (iii) If the final carry over of the sum is 1, it is dropped and the result is positive. (iv) If there is no carry over, the two’s complement of the sum will be the result and it is negative. binary numbers. 29

31 (Cont’d) Example 1  Given the two binary numbers X = 1010100 and Y = 1000011, perform the subtraction (a) X – Y ; and (b) Y  X, by using 2's complement. Solution: There is no end carry. Therefore, the answer is Y – X =  (2's complement of 1101111) =  0010001. 30

32 2.5Signed Numbers To represent negative integers, we need a notation for negative values. It is customary to represent the sign with a bit placed in the leftmost position of the number since binary digits. The convention is to make the sign bit 0 for positive and 1 for negative. Example: -9 31

33 S igned Binary Numbers (Cont’d) Arithmetic addition  The addition of two numbers in the signed-magnitude system follows the rules of ordinary arithmetic. If the signs are the same, we add the two magnitudes and give the sum the common sign. If the signs are different, we subtract the smaller magnitude from the larger and give the difference the sign if the larger magnitude.  The addition of two signed binary numbers with negative numbers represented in signed-2's-complement form is obtained from the addition of the two numbers, including their sign bits.  A carry out of the sign-bit position is discarded. Example: 32

34 Signed Binary Numbers (Cont’d) Arithmetic Subtraction  In 2’s-complement form: Example: 1.Take the 2’s complement of the subtrahend (including the sign bit) and add it to the minuend (including sign bit). 2.A carry out of sign-bit position is discarded. (  6)  (  13)(11111010  11110011) (11111010 + 00001101) 00000111 (+ 7) 33

35 Binary Subtraction Borrow a “Base” when needed 001110 11110 − 0101110 = (10) 2 2 2 2 2 1 000 1 = 77 = 23 = 54 34

36 2.7 BCD BCD Code  A number with k decimal digits will require 4k bits in BCD.  Decimal 396 is represented in BCD with 12bits as 0011 1001 0110, with each group of 4 bits representing one decimal digit.  A decimal number in BCD is the same as its equivalent binary number only when the number is between 0 and 9.  The binary combinations 1010 through 1111 are not used and have no meaning in BCD. 35

37 2.7 BCD Example:  Consider decimal 185 and its corresponding value in BCD and binary: BCD addition 36

38 2.7 BCD Example:  Consider the addition of 184 + 576 = 760 in BCD : 37


Download ppt "Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1."

Similar presentations


Ads by Google