27
1 Learning outcomes Review number systems Explain how powers of ten are used in the decimal system Determine the weight of each digit in a decimal number Convert from decimal to binary and from binary to decimal Count in the binary number system Determine the 1's and 2's complements of a binary number Express negative binary numbers in 2' s complement Perform arithmetic operations to binary numbers Convert between the binary and hexadecimal number systems Convert between the binary and octal number systems Convert between decimal and hexadecimal number systems Convert between decimal and octal number systems

Digital Logic L1

Embed Size (px)

Citation preview

Page 1: Digital Logic L1

1

Learning outcomes

• Review number systems• Explain how powers of ten are used in the decimal system• Determine the weight of each digit in a decimal number• Convert from decimal to binary and from binary to decimal• Count in the binary number system • Determine the 1's and 2's complements of a binary number • Express negative binary numbers in 2' s complement• Perform arithmetic operations to binary numbers• Convert between the binary and hexadecimal number systems • Convert between the binary and octal number systems • Convert between decimal and hexadecimal number systems• Convert between decimal and octal number systems

Page 2: Digital Logic L1

2

Number Systems

Number system – a system of base or radix, r, is a system that uses distinct symbols for r digits.

NrBase or radix

Number or digit symbol

Base or radix – number of digits which can occur in the number system

Examples:

Base 10 (10 digits) Base 16 (16 digits)

Base 8 (8 digits) Base 2 (2 digits)Can you name more?

Page 3: Digital Logic L1

3

Number Systems

Nr = (an-1 an-2 ….. a1 a0 . a-1 a-2 ….a-m)r

Integer part Fractional partRadix point

Example:

In decimal: (435.301)10

Page 4: Digital Logic L1

4

Number Systems

Base 16 – Hexadecimal number

used for addressing in microprocessors and to express binary numbers

Base 10 – Decimal number

used in everyday life for mathematical calculations

Base 8 – Octal number

also used to represent binary numbers

Base 2 – Binary number

used in digital processing in electronic circuits

Page 5: Digital Logic L1

5

Decimal Number

Total 654.52

0.020.5450600Weighted Value

25456Digits

10-210-1100101102Weights

One hundredth

One tenth

UnitsTensHundreds

For the decimal number system:

1. Number of digits is 10: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

2. The base is 10

3. The value of the digit is determined by the position of the number(654.52)10

Decimal point

Page 6: Digital Logic L1

6

Binary NumberThe binary number:

1. Has base 2 i.e. is represented by 2 digits: 0 and 1

2. The position of a 1 or 0 in a binary number indicates its weight or value within the number.

3. The weights in a binary number are based on powers of two.

01011Digits

2-22-1202122Weights

Binary point

(110.10)2

The most significant bit (MSB) is the leftmost binary digit which has the highest binary weight of a given number.

The least significant bit (LSB) is the rightmost binary digit which has the lowest binary weight of a given number.

MSB LSB MSB LSB

Page 7: Digital Logic L1

7

Binary to Decimal ConversionThe decimal value of any binary number can be found by adding the weights of all bits that are 1 and discarding the weights of all bits that are 0.

Ex. Convert (110101)2 to decimal form.

Total (53)10

10401632Decimal Value

101011Binary Number

12481632Weight Value

202122232425Binary Weights

Convert the binary numbers to decimal:1. 100100012. 0.10113. 1101.11

Page 8: Digital Logic L1

8

Decimal to Binary Conversion2 methods of converting a decimal number to binary:

1. Sum of weights

2. Repeated division by two.

1. Sum of weights method.Determine the set of binary weights whose sum is equal to the decimal number.

00011BinaryNumber

124816Weight Value

2021222324Binary Weights

Convert (24)10 to binary

Answer: (11000)2

Disadvantage:

1. Time consuming

Convert (1456)10 to binary

Page 9: Digital Logic L1

9

Decimal to Binary Conversion2. Repeated-Division-by-2 method

1. Divide the quotient by two and record the remainder.

2. Repeat step (a) until the quotient is equal to zero (0).

3. The first remainder produced is the LSB in the binary number and the last remainder (R) the MSB.

4. The binary number is then written (from left to right) with the MSB occurring first.

Procedure:Converting (18)10 to binary

R 1 (MSB)0

R 012

R 022

R 142

R 0 (LSB)92

182

Therefore, (18)10 = (10010)2

Convert the following decimal numbers to binary: (a) 12 (c) 82 (b) 25 (d) 58

Page 10: Digital Logic L1

10

Decimal fractions to BinarySum-oF-Weights:

The sum-of-weights method can be applied to fractional decimal numbers:

Ex: 0.625 = 0.5 + 0.125 = 2-1 + 2-3 = 0.101

Repeated multiplication by 2

For example: Convert 0.3125 to binary,

1. Begin by multiplying 0.3125 by 2 and then multiplying each resulting fractional part of the product by 2 until the fractional product is zero or until the desired number of decimal places is reached.

2. The carry digits, or carries, generated by the multiplications produce the binary number.

3. The first carry produced is the MSB, and the last carry is the LSB.

Page 11: Digital Logic L1

11

Decimal fractions to Binary

14

Page 12: Digital Logic L1

12

Binary Arithmetic - Addition

101+1011+0010+1000+0

CarrySumA+BAddition Rules

The four basic rules for adding binarydigits (bits) are as follows:

Word A: A3 A2 A1 A0

Word B: B3 B2 B1 B0

SUM: S3 S2 S1 S0

CARRY: C3 C2 C1 C0

1 0 0 08+ 0 1 1+3

1 0 15BinaryDecimal

Example of binary addition:

Try: (158)10 + (12)10(111)2 + (1011)2(1010)2 + (1010)2( 23)10 + ( 15)10

Addition of two 4-bit words A and B

Page 13: Digital Logic L1

13

Binary Arithmetic - SubtractionTwo efficient methods that can be implemented with hardware are:

1. Subtraction using 1’s complement.

2. Subtraction using 2’s complement.

The 1's complement of a binary number is found by changing:1. all 1s to 0s and2. all 0s to 1s,

1’s complement of binary numbers

1 0 1 1 0 1 0 1

0 1 0 0 1 0 1 0

Obtain the 1’s complement of (11010110)2 and (654)10

Complements are used in digital computers for simplifying the subtraction operationand for logical manipulation.

Page 14: Digital Logic L1

14

Binary Arithmetic - Subtraction2’s complement of binary numbers

The 2's complement of a binary number is found by adding 1 to the LSB of the1's complement.

2's complement = (1's complement) + 1

0 0 1 1 00 0 0 0 10 0 1 1 1

Add 12’s complement

0 0 1 1 01’s complement1 1 0 0 1Binary number

(25)10Decimal number

+

Obtain the 2’s complement of:

1. (110111)2

2. (56)10

Page 15: Digital Logic L1

15

Binary Arithmetic - Subtraction

The subtraction of two n-digit unsigned numbers M - N in base 2 can be done as follows:

1. Add the minuend M to the 2’s complement of the subtrahend N.

2. If M ≥ N, the sum will produce an end carry which is discarded

3. If M < N, the sum does not produce an end carry the result is equal to the2’s complement of (N - M). To obtain the correct answer, take the 2's complement of the sum and place a negative sign in front.

-Minuend M

Subtrahend N

Page 16: Digital Logic L1

16

Binary Arithmetic - SubtractionGiven two binary numbers X = 1010100 and Y = 1000011, perform the subtractions: X – Y and Y – X using 2’s complements.

Try X – Y and Y – X when

1. X = 78 and Y = 87;

2. X = 45 and Y = 45

3. X = 19 and Y = 49

All numbers are in base 10.

Page 17: Digital Logic L1

17

Hexadecimal NumbersThe hexadecimal number system1. Has a base of sixteen; that is, it is composed of 16 numeric and

alphabetic characters: 0,1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F2. Has weights based on powers of 163. The position of a character in the number indicates its weight or value

within the number

16-216-1.160161162Weights

Hexadecimal point

Example: (14A)16, (BA)16

Page 18: Digital Logic L1

18

Hexadecimal Numbers

F111115

E111014

D110113

C110012

B101111

A101010

910019810008701117601106501015401004300113200102100011000000

HexadecimalBinaryDecimal

Each 4-bit binary number can be represented by a hexadecimal number.

Ex.

(0000)2 – (0)16

(1100)2 - CH

Page 19: Digital Logic L1

19

Hexadecimal to BinaryConverting Hexadecimal to Binary

Because each hexadecimal digit can be represented by a four-bit binary number it is very easy to convert from hexadecimal to binary. Replace each hexadecimal digit with the appropriate four-bit binary number.

Examples

A 3 16 = (1010 0011) 2

(37.12) 16 = (00110111.00010010) 2

Convert the following to binary form

ABCH; 1B0H; DE4H; AC5H

Page 20: Digital Logic L1

20

Binary to Hexadecimal Converting Binary to Hexadecimal

Break the binary digits into groups of four starting from the binary point and convert each group into its appropriate hexadecimal digit using the conversion table.For whole numbers, it may be necessary to add a zero as the MSB in order to complete a grouping of four bits.

Example:

(101001)2 => (00101001)2 => 29H

(110 1100 1111)2 => (0110 1100 1111)2 => 6CFH

Convert the following to hexadecimal form

(11011111)2; (011001111)2; (110111)2; (011001)2

Page 21: Digital Logic L1

21

Hexadecimal to DecimalConverting Hexadecimal to Decimal

To convert a hexadecimal number to its decimal equivalent - multiply the decimal value of each hexadecimal digit by its weight and then take the sum of these products.

21110Decimal Value of Hex

2BAHexadecimal Number

116256Weight Value

160

161162Hexadecimal Weights

21762560Decimal Value

Answer: (1738)10

Convert AB2 to Decimal

Convert the following hexadecimal numbers to decimal:

1. ADF

2. ACF

3. 32A

4. 1234

Page 22: Digital Logic L1

22

Decimal to HexadecimalConverting Decimal to hexadecimal

Successive division of decimal number by 16.

1. Divide the quotient by 16 and record the remainder (R).

2. Repeat step (a) until the quotient is equal to zero (0).

3. The first remainder produced is the LSB in the hexadecimal number and the last remainder the MSB.

4. The hexadecimal number is then written (from left to right) with the MSB occurring first.

R 3 (MSB)0R 5316R 6 (LSB)5316

85416

Example: (854)10 to hex

Answer: 356H

Convert the following to hexadecimal:

1. (54)10

2. (81)10

3. (719)10

Page 23: Digital Logic L1

23

Octal Numbers

8-28-1.808182Octal Weights

The octal number system1. Has a base of eight; that is, it is composed of 8 numeric characters: 0,1,

2, 3, 4, 5, 6, 72. Has weights based on powers of 83. The position of a character in the number indicates its weight or value

within the number

Hexadecimal point

Examples : (33)8; (1235)8

Page 24: Digital Logic L1

24

Octal to Binary

11171106101510040113010200110000

Binary DigitOctal Digit

The primary application of octal numbers is representing binary numbers, as it is easier to read large numbers in octal form that in binary form. Because each octal digit can be represented by a three-bit binary number it is very easy to convert from octal to binary.

(37.12) 8 = (011111. 001010) 2

13 8 = (001011) 2

Conversion of octal to binary

Convert the following numbers to binary:

(254)8; (265)8; (159)10; (954)10

Page 25: Digital Logic L1

25

Binary to Octal Converting Binary to Octal

Break the binary digits into groups of three starting from the binary point and convert each group into its appropriate octal digit.

For whole numbers, it may be necessary to add a zero as the MSB in order to complete a grouping of three bits. Note that this does not change the value of the binary number.

Examples:

1.Converting (010111) 2 to Octal

111 = 7 (LSB)

010 = 2 (MSB)

thus, (010111) 2 = (27) 8

Convert the following binary numbers to octal:

(11011111)2; (011001111)2; (110111)2; (011001)2

Page 26: Digital Logic L1

26

Octal to DecimalTo express the value of a given octal number as its decimal equivalent we just need to sum the digits after each has been multiplied by its associated weight.

Convert (237.04) 8 to decimal form.

Total (159.0625)10

0.06250724128Decimal Value

40732Octal Number

0.0156250.1251864Weight Value8-28-1808182Weights

Answer: (159.0625)10

Convert to decimal form:(125) 8 (568) 8 (25) 8

Page 27: Digital Logic L1

27

Decimal to OctalRepeated-Division-by-8 method

a. Divide the quotient by eight and record the remainder.b. Repeat step (a) until the quotient is equal to zero (0).c. The first remainder produced is the LSB in the octal number and the last

remainder (R) the MSB. Accordingly, the octal number is then written (from left to right) with the MSB occurring first

Converting (359) 10 to Octal

R 5 (MSB)08R 458R 7 (LSB)448

3598

(359) 10 = (547) 8

Convert the following to octal:

1. (514)10

2. (381)10

3. (71)10