1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2...

63
1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS

Transcript of 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2...

Page 1: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

1

CHAPTER 1 DIGITAL SYSTEMS AND BINARY

NUMBERS

Page 2: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

2

OUTLINE OF CHAPTER 1

1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal and Hexadecimal Numbers 1.5 Complements 1.6 Signed Binary Numbers 1.7 Binary Codes 1.8 Binary Storage and Registers 1.9 Binary Logic

2

Page 3: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

3

DIGITAL SYSTEMS AND BINARY NUMBERS

Digital computers General purposes Many scientific, industrial and commercial

applications Digital systems

Digital Telephone Digital camera Electronic calculators Digital TV

Discrete information-processing systems Manipulate discrete elements of information For example, {1, 2, 3, …} and {A, B, C, …}…

3

Page 4: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

4

ANALOG AND DIGITAL SIGNAL Analog system

The physical quantities or signals may vary continuously over a specified range.

Digital system The physical quantities or signals can assume only

discrete values.

t

X(t)

t

X(t)

Analog signal Digital signal

4

Page 5: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

5

BINARY DIGITAL SIGNAL

For digital systems, the variable takes on discrete values. Two level, or binary values.

Binary values are represented abstractly by: Digits 0 and 1 Words (symbols) False (F) and True (T) Words (symbols) Low (L) and High (H) And words Off and On

Page 6: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

6

DECIMAL NUMBER SYSTEM

Base (also called radix) = 10 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }

Digit Position Integer & fraction

Digit Weight Weight = (Base) Position

Magnitude Sum of “Digit x Weight”

Formal Notation

1 0 -12 -2

5 1 2 7 4

10 1 0.1100 0.01

500 10 2 0.7 0.04

d2*B2+d1*B

1+d0*B0+d-1*B

-1+d-2*B-2

(512.74)10

6

Page 7: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

7

OCTAL NUMBER SYSTEM

Base = 8 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }

Weights Weight = (Base) Position

Magnitude Sum of “Digit x Weight”

Formal Notation1 0 -12 -2

8 1 1/864 1/64

5 1 2 7 4

5 *82+1 *81+2 *80+7 *8-1+4 *8-2

=(330.9375)10

(512.74)8

7

Page 8: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

8

BINARY NUMBER SYSTEM Base = 2

2 digits { 0, 1 }, called binary digits or “bits” Weights

Weight = (Base) Position

Magnitude Sum of “Bit x Weight”

Formal Notation Groups of bits 8 bits = Byte

1 0 -12 -2

2 1 1/24 1/4

1 0 1 0 1

1 *22+0 *21+1 *20+0 *2-1+1 *2-2

=(5.25)10

(101.01)21 1 0 0 0 1 0 1

8

Page 9: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

9

HEXADECIMAL NUMBER SYSTEM

Base = 16 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }

Weights Weight = (Base) Position

Magnitude Sum of “Digit x Weight”

Formal Notation1 0 -12 -2

16 1 1/16256 1/256

1 E 5 7 A

1 *162+14 *161+5 *160+7 *16-1+10 *16-2

=(485.4765625)10

(1E5.7A)16

9

Page 10: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

10

THE POWER OF 2

n 2n

0 20=1

1 21=2

2 22=4

3 23=8

4 24=16

5 25=32

6 26=64

7 27=128

n 2n

8 28=256

9 29=512

10 210=1024

11 211=2048

12 212=4096

20 220=1M

30 230=1G

40 240=1T

Mega

Giga

Tera

Kilo

10

Page 11: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

11

ADDITION

Decimal Addition

5 5

55+

011

= Ten ≥ Base

Subtract a Base

11 Carry

11

Page 12: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

12

BINARY ADDITION

Column Addition

1 0 1111

1111 0+

0000 1 11

≥ (2)10

111111

= 61

= 23= 84

12

Page 13: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

13

BINARY SUBTRACTION

Borrow a “Base” when needed

0 0 1110

1111 0−

0101 1 10

= (10)22

22 2

1

000

1

= 77

= 23= 54

13

Page 14: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

14

BINARY MULTIPLICATION

Bit by bit

01 1 1 1

01 1 0

00 0 0 0

01 1 1 1

01 1 1 1

0 0 000

0110111 0

x

14

Page 15: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

15

NUMBER BASE CONVERSIONS

Decimal(Base 10)

Octal(Base 8)

Binary(Base 2)

Hexadecimal(Base 16)

Evaluate Magnitude

Evaluate Magnitude

Evaluate Magnitude

15

Page 16: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

16

DECIMAL (INTEGER) TO BINARY CONVERSION

Divide the number by the ‘Base’ (=2) Take the remainder (either 0 or 1) as a coefficient Take the quotient and repeat the division

Example: (13)10

Quotient Remainder Coefficient

Answer: (13)10 = (a3 a2 a1 a0)2 = (1101)2

MSB LSBMSB LSB

13/ 2 = 6 1 a0 = 1 6/ 2 = 3 0 a1 = 0 3/ 2 = 1 1 a2 = 1 1/ 2 = 0 1 a3 = 1

16

Page 17: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

17

DECIMAL (FRACTION) TO BINARY CONVERSION

Multiply the number by the ‘Base’ (=2) Take the integer (either 0 or 1) as a coefficient Take the resultant fraction and repeat the

multiplication

Example: (0.625)10

Integer Fraction Coefficient

Answer: (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2

MSB LSBMSB LSB

0.625* 2 = 1 . 250.25* 2 = 0 . 5 a-2 = 00.5 * 2 = 1 . 0 a-3 = 1

a-1 = 1

17

Page 18: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

18

DECIMAL TO OCTAL CONVERSION

Example: (175)10

Quotient Remainder Coefficient

Answer: (175)10 = (a2 a1 a0)8 = (257)8

175/ 8 = 21 7 a0 = 7 21/ 8 = 2 5 a1 = 5 2 / 8 = 0 2 a2 = 2

Example: (0.3125)10

Integer Fraction Coefficient

Answer: (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8

0.3125* 8 = 2 . 50.5 * 8 = 4 . 0 a-2 = 4

a-1 = 2

18

Page 19: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

19

BINARY − OCTAL CONVERSION

8 = 23

Each group of 3 bits represents an octal digit

Octal Binary

0 0 0 0

1 0 0 1

2 0 1 0

3 0 1 1

4 1 0 0

5 1 0 1

6 1 1 0

7 1 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)

19

Page 20: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

20

BINARY − HEXADECIMAL CONVERSION

16 = 24

Each group of 4 bits represents a hexadecimal digit

Hex Binary0 0 0 0 01 0 0 0 12 0 0 1 03 0 0 1 14 0 1 0 05 0 1 0 16 0 1 1 07 0 1 1 18 1 0 0 09 1 0 0 1A 1 0 1 0B 1 0 1 1C 1 1 0 0D 1 1 0 1E 1 1 1 0F 1 1 1 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)

20

Page 21: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

21

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

21

Page 22: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

22

DECIMAL, BINARY, OCTAL AND HEXADECIMAL

Decimal Binary Octal Hex00 0000 00 001 0001 01 102 0010 02 203 0011 03 304 0100 04 405 0101 05 506 0110 06 607 0111 07 708 1000 10 809 1001 11 910 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E15 1111 17 F

22

Page 23: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

23

COMPLEMENTS There are two types of complements for each base-r system: the radix

complement and diminished radix complement. Diminished Radix Complement (r-1)’s Complement

Given a number N in base r having n digits, the (r–1)’s complement of N is defined as:

(rn –1) – N Example for 4-digit decimal numbers:

9’s complement is (rn – 1)–N = (104–1)–N = 9999–N 9’s complement of 4670 is 9999–4670 = 5329

Example for 4-digit binary numbers: 1’s complement is (rn – 1) – N = (24–1)–N = 1111–N 1’s complement of 1100 is 1111–1100 = 0011

Observation: Subtraction from (rn – 1) will never require a borrow For binary: 1 – 0 = 1 and 1 – 1 = 0

23

Page 24: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

24

COMPLEMENTS 1’s Complement (Diminished Radix Complement)

All ‘0’s become ‘1’s All ‘1’s become ‘0’sExample (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 11 1 1 1 1 1 1

124

Page 25: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

25

COMPLEMENTS Radix Complement

Example: Base-10

Example: Base-2

The r's complement of an n-digit number N in base r is defined as rn – N for N ≠ 0 . Comparing with the (r 1) 's complement, we note that the r's complement is obtained by adding 1 to the (r 1) 's complement, since rn – N = [(rn 1) – N] + 1.

The 10's complement of 012398 is 987602The 10's complement of 4670 is 5330

The 2's complement of 1101100 is 0010100 The 2's complement of 0110111 is 1001001

25

Page 26: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

26

COMPLEMENTS 2’s Complement (Radix Complement)

Take 1’s complement then add 1 Toggle all bits to the left of the first ‘1’ from the rightExample: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

OR

1 0 1 1 0 0 0 0

00001010

26

Page 27: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

27

COMPLEMENTS

Subtraction with Complements The subtraction of two n-digit unsigned numbers M

– N in base r can be done as follows:

27

Page 28: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

28

COMPLEMENTS Example 1.5

Using 10's complement, subtract 72532 – 3250.

Example 1.6 Using 10's complement, subtract 3250 – 72532.

There is no end carry.

Therefore, the answer is – (10's complement of 30718) = 69282.

28

Page 29: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

29

COMPLEMENTS Example 1.7

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.

There is no end carry. Therefore, the answer is Y – X = (2's complement of 1101111) = 0010001.

29

Page 30: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

30

COMPLEMENTS Subtraction of unsigned numbers can also be done by means

of the (r 1)'s complement. Remember that the (r 1) 's complement is one less then the r's complement.

Example 1.8 Repeat Example 1.7, but this time using 1's complement.

There is no end carry, Therefore, the answer is Y – X = (1's complement of 1101110) = 0010001.

+

30

Page 31: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

31

SIGNED BINARY NUMBERS

To represent negative integers, we need a notation for negative values.

Signed-magnitude represents the sign with a bit placed in the leftmost position of the number and the rest of the bits represent the number.

The convention is to make the sign bit 0 for positive and 1 for negative.

Example: +9 is represented only by 00001001

three different ways to represent -9

31

Page 32: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

3232

Table 1.3 lists all possible four-bit signed binary numbers in the three representations.

2n-1-1

-(2n-1-1)

Page 33: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

33

SIGNED BINARY NUMBERS 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 of 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:

33

Page 34: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

34

The main problem with signed-magnitude system is that it doesn’t support binary arithmetic (which is what the computer would naturally do). That is, if you add 10 and -10 binary you won’t get 0 as a result.

00001010 (decimal 10) (signed-magnitude) +10001010 (decimal -10) -------------------------------- 10010100 (decimal -20) (wrong answer)

Page 35: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

35

00001100 (decimal 12) +11110011 (decimal -12) (1’s complement)-------------------------------- 11111111 (decimal -0)

00000011 (decimal 3) +11111101 (decimal -2) (1’s complement) ------------------------------- 100000000 (decimal 256)

If we have only 8 bits to represent the numbers, the leftmost 1 will be discarded, and the result would be 00000000 (decimal +0).

Page 36: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

36

SIGNED BINARY NUMBERS

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.( ) ( ) ( ) ( )

( ) ( ) ( ) ( )

A B A B

A B A B

( 6) ( 13) (11111010 11110011)

(11111010 + 00001101)

00000111 (+ 7)36

Page 37: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

37

The problems of a part of chapter one tha will be solved this week are :

1.2, 1.3, 1.4, 1.5, 1.7, 1.8, 1.9, 1.12, 1.13, 1.14(a,c), 1.15(a,c), 1.16, 1.17(a,b), 1.18(a,c)

Page 38: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

38

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.

BCD numbers are decimal numbers and not binary numbers, although they use bits in their representation. The only difference between a decimal number and BCD is that decimals are written with the symbols 0, 1, 2, . . . , 9 and BCD numbers use the binary code 0000, 0001, 0010. . . . . 1001.

When the binary sum is equal to or less than 1001 (without a carry), the corresponding BCD digit is correct. However, when the binary sum is greater than or equal to 1010, the result is an invalid BCD digit.

BINARY CODES

Page 39: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

39

BCD Code (Decimal computers) 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.

BCD is very common in electronic systems where a numeric value is to be displayed, especially in systems consisting only of digital logic, and not containing a microprocessor. 39

Page 40: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

40

BINARY CODE Example:

Consider decimal 185 and its corresponding value in BCD (it is decimal number) and binary:

BCD addition

40

Page 41: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

41

BINARY CODE

Example: Consider the addition of 184 + 576 = 760 in

BCD:

Decimal Arithmetic: (+375) + (-240) = +135

41

Page 42: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

42

BINARY CODES

Other Decimal Codes

42

Page 43: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

43

BCD is named also 8421 code. BCD and 2421 code are examples of weighted

codes.

Some digits can be coded in two possible ways in the 2421 code. (4 can be assigned to 0100 or 1010).

The excess-3 code is an unweighted code.

The 2421 and the excess-3 codes are examples of self-complementing codes. 9’s complement of a decimal number is obtained directly by complementing each bit.

604 ----- (1001 0011 0111) 999 – 604 = 395 ----- (0110 1100 1000)

43

Page 44: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

44

The 8, 4, -2, -1 code is an example of assigning both positive and negative weights to a decimal code.

When you add two XS-3 numbers together, the result is not an XS-3 number. For instance, when you add 1 (0100) and 0 (0011) in XS-3 the answer seems to be 4 (0111) instead of 1 (0100). In order to correct this problem, when you are finished adding each digit, you have to subtract 3 (binary 0011) if the digit is less than decimal 10 and add three if the number is greater than or equal to decimal 10.

1 + 9 = 10 0100 + 1100 = 10000 (there is carry , this means

answer > 9). The true answer is (0100 0011) You need to add 0011 to each digit.

Page 45: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

45

BINARY CODES Gray Code

The advantage is that only bit in the code group changes in going from one number to the next. Error detection. (it prevents

data errors which can occur with natural binary during state changes)

Representation of analog data.000 001

010100

110 111

101011

45

Page 46: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

46

GRAY CODE 1010 (natural binary number) ---- 1111 Most left bit is the same. Add each two bits in the binary number starting

from the left. 0 + 0 = 0 1 + 0 =1 1 + 1 = 0 (discard carry) 1111 (gray code) ---- 1010 Most left bit is the same. Add the generated bit in the natural binary to the

next gray code bit (to the right). One of the application is the rotary encoder on the

motor shaft to control the angular position by a controller such as microcontroller) (in robot arm).

46

Page 47: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

47

ASCII CHARACTER CODES

American Standard Code for Information Interchange (Refer to Table 1.7)

A popular code used to represent information sent as character-based data.

It uses 7-bits to represent: 94 Graphic printing characters. 34 Non-printing characters (Control Characters).

Some non-printing characters are used for text format (e.g. BS = Backspace, CR = carriage return). (Format effectors)

Other non-printing characters are Communication CC (e.g. STX and ETX start and end text areas).

Information separators are used to separate the data into divisions such as paragraphs and pages.

47

Page 48: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

48

ASCII CHARACTER CODE American Standard Code for Information Interchange

(ASCII) Character Code

48

Page 49: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

49

ASCII Character Code

49

Page 50: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

50

ASCII PROPERTIES

The seven bits of the code are designated by b1 through b7. with b7 the most significant bit.

The letter A. for example is represented in ASCII as 1000001 (column 100, row 0001).

ASCII has some interesting properties: Digits 0 to 9 span Hexadecimal values 3016 to 3916

Upper case A-Z span 4116 to 5A16

Lower case a-z span 6116 to 7A16

Lower to upper case translation (and vice versa) occurs by flipping bit 6.

50

Page 51: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

51

ASCII is a seven-bit code, but most computers manipulate an eight-bit quantity as a single unit called a byte. Therefore, ASCII characters often are stored one per byte.

Extended ASCII (8 bits) adds the Greek alphabets.

Page 52: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

52

BINARY CODES

Error-Detecting Code To detect errors in data communication and

processing, an eighth bit is sometimes added to the ASCII character to indicate its parity.

A parity bit is an extra bit included with a message to make the total number of 1's either even or odd.

Example: Consider the following two characters and their

even and odd parity:

52

Page 53: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

53

BINARY CODES Error-Detecting Code

Parity can detect all single-bit errors. A code word has even parity if the number of 1’s in

the code word is even. A code word has odd parity if the number of 1’s in

the code word is odd. Example:

If the receiver detects a parity error, it sends back ASCII NAK. If no error is detected, the receiver sends back ACK.

10001001

10001001

1

0(odd parity)Message B:

Message A: (even parity)

53

Page 54: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

54

BINARY STORAGE AND REGISTERS

Registers A binary cell is a device that possesses two stable states

and is capable of storing one of the two states. A register is a group of binary cells. A register with n cells

can store any discrete quantity of information that contains n bits.

A binary cell Two stable state Store one bit of information Examples: flip-flop circuits

A register A group of binary cells AX in x86 CPU

Register Transfer A transfer of the information stored in one register to another. One of the major operations in digital system.

n cells 2n possible states (1100001111001001)50,121 CI (ASCII with even parity)Ex-3: 9096 BCD ??? (meaningless)

54

Page 55: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

55

TRANSFER OF INFORMATION

Figure 1.1 Transfer of information among register

55

Page 56: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

56

TRANSFER OF INFORMATION

Circuit elements to manipulate individual bits of information

Load-store machineLD R1; LD R2;ADD R3,

R2, R1;SD R3;

Figure 1.2 Example of binary information processing

56

Page 57: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

57

BINARY LOGIC (BOOLEAN ALGEBRA) Definition of Binary Logic

Binary logic consists of binary variables and a set of logical operations.

The variables are designated by letters of the alphabet, such as A, B, C, x, y, z, etc, with each variable having two and only two distinct possible values: 1 and 0,

Three basic logical operations: AND, OR, and NOT.

57

Page 58: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

58

BINARY LOGIC

Truth Tables, Boolean Expressions, and Logic Gates

xy z

x y z

0 0 0

0 1 0

1 0 0

1 1 1

x y z

0 0 0

0 1 1

1 0 1

1 1 1

x z

0 1

1 0

AND OR NOT

xy z

z = x • y = x y

z = x + y z = x = x’

x z

Page 59: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

59

SWITCHING CIRCUITS

AND OR

59

Page 60: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

60

LOGIC GATES Logic gates are electronic circuits that operate on one

or more input signals to produce an output signal.

0

1

2

3Logic 1

Logic 0

Un-define

Figure 1.3 Example of binary signals

60

Page 61: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

61

LOGIC GATESGraphic Symbols and Input-Output Signals for

Logic gates:

Fig. 1.4 Symbols for digital logic circuits

Fig. 1.5 Input-Output signals for gates

61

Page 62: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

62

Logic gates Graphic Symbols and Input-Output Signals for

Logic gates with multiple inputs:

62

Page 63: 1 CHAPTER 1 DIGITAL SYSTEMS AND BINARY NUMBERS 2 O UTLINE OF C HAPTER 1 1.1 Digital Systems 1.2 Binary Numbers 1.3 Number-base Conversions 1.4 Octal.

63

The problems of chapter one that will be solved are:

1.19, 1.20, 1.21, 1.22, 1.23, 1.26,

1.28, 1.30, 1.32, 1.33, 1.35