0% found this document useful (0 votes)
32 views

Capter 2

Digital Logic

Uploaded by

Roha Cbc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Capter 2

Digital Logic

Uploaded by

Roha Cbc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 48

1

CHAPTER 2 :
NUMBER SYSTEM, OPERATION
AND CODES
Chapter 2 :
2 NUMBER SYSTEM, OPERATION AND CODES
 2.1 Decimal Number
 2.2 Binary Number
 2.3 a) Binary-to-Decimal Conversion
b) Decimal-to-Binary Conversion
 2.8 Hexadecimal Numbers
 2.9 Octal Number
 2.10 Binary Coded Decimal (BCD)
 2.11 Digital Codes and Parity
 Digital System Application
2.1 Decimal Number
3  The decimal numbering system has 10 digits 0 through 9

 The decimal numbering system has a base of 10 with each


position weighted by a factor of 10

 ….105 104 103 102 101 100. 10-110-2 10-3 10-4 10-5…
 Example :
Express decimal 47 as a sum of the values of each digit :
47 = (4 x 101) + (7 x 100)
= 40 + 7
= 47
2.2 Binary Number
4  The binary numbering system has 2 digits 0 and 1

 The binary numbering system has a base of 2 with each


position weighted by a factor of 2

24 23 22 21 20 2-1 2-2 2-3 2-4 2-5

increase increase

 Example :
101112 = (1 X 24 + 0 X 23 + 1 X 22 + 1 X 21 + 1 X 20 )
24 23 22 21 20

1 0 1 1 1
1x16 0x8 1x4 1x2 1x1

16 0 4 2 1

16 + 4 + 2 + 1 = 2310
5
2.3 a) Binary-to-Decimal Conversion
6
 Convert binary to decimal by summing the positions that
contain a 1

1 0 0 1 0 12
5 4 3 2 1 0
2  2  2  2  2  2  32  4  1  3710
Binary Count

7
Binary-to-Decimal Conversion
8

 Step 1: Get n, total binary numbers


 1101101  n = 7 binary numbers
 Step 2: Conversion will stop at 2n-1 = 26
 Step 3: Multiply all the numbers with its appropriate
weight
 Step 4: Sum the result from step 3, and binary is now
decimal.
 Step 1: Binary number: 100101  n = 6
9  Step 2: Stop at 2n-1 = 25

1 0 0 1 0 1
Step 3: 25 24 23 22 21 20
multiply
= 32 0 0 4 0 1
Step 4:
sum +
37

25 24 23 22 21 20
32 16 8 4 2 1
2.3 b) Decimal-to-Binary Conversion
10

 Two methods to convert decimal to binary:


 1) Sum-of-weights method (reverse
process)
 Determine the set of binary weights whose
sum is equal to the decimal number

 2) Repeated division-by-2 method


 Repeatedly dividing the decimal number by 2
and retrieving the remainder
1) Sum-of-weight method
11
Binary weights
256 128 64 32 16 8 4 2 1
357 = 256 + 64 + 32 + 4 + 1 101100101
= 29 + 27 + 26 + 22 + 20

Binary weights
1024 512 256 128 64 32 16 8 4 2 1
1937 = 1024 + 512 + 256 + 128 + 16 + 1 11110010001
1) Sum-of-weight method

12
58
minus
Nearest weight to 58
32 32 16 8 2
26 Apply a 1 to these
minus
weights and 0 to others
16
10
minus
8
2
minus
2 25 24 23 22 21 20

0 32 16 8 4 2 1
1 1 1 0 1 0
5810 = 1110102
1) Sum-of-weight method
82
minus
64 64 16 2
18 Apply a 1 to these
minus
weights and 0 to others
16
2
minus
2
0
26 25 24 23 22 21 20

64 32 16 8 4 2 1
1 0 1 0 0 1 0
13
1) Sum-of-weight method
 Try this for 25 and 125
14

25 125
minus minus
16 64 64 32 16 8 4 1
16 8 1
9 61 Apply a 1 to these
Apply a 1 to these minus
minus weights and 0 to others
weights and 0 to others 32
8
29
1 minus
minus 16
1
13
0 8
minus 26 25 24 23 22 21 20
24 23 22 21 20 64 32 16 8 4 2 1
5
minus
16 8 4 2 1 4 1 1 1 1 1 0 1
1 1 0 0 1 1
minus
1
0
Repeated division-by-2
15

 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.
 This flowchart describes the
16 process and can be used to convert
from decimal to any other number
system.
1210 = X2 Remainder

12 = 6 0
Right/LSB

6 = 3 0
2 1 1 0 0

3 = 1 1
2

1 = 0 1
2 Left/MSB

17
Stop when the
quotient = 0
4510 = Y2 Remainder

45 = 22 1
Right/LSB

2
22 = 11 0
2
11 = 5 1 0 1 1 0 1
1
2
5 = 2 1
2
2 = 1 0
2
1 = 0 1
18
2 Left/MSB
Converting Decimal Fractions-to-Binary
19

 2 ways to convert:
 1) Sum-of-weight
 2) Repeated multiplication of 2

2 -1 2 -2 2 -3 2 -4

0.5 0.25 0.125 0.0625

divide by 2 from
previous value
1) Sum-of-weights
20
0.625
m inus
0.5 0.125
0.5 Apply 1 to the
above, others 0
0.125
m inus
0.125
0

2 -1 2 -2 2 -3 2 -4

0.5 0.25 0.125 0.0625


1 0 1 0

0.625 10 = 0.101 2
2) Repeated multiplication by 2
21
 Conversion of decimal-binary
 Whole numbers  repeated division by 2
 Fractions  repeated multiplication by 2
 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
carry
left/MSB
0.3125 x 2 = 0.625 0

0.625 x 2 = 1.25 1
. 0 1 0 1

0.25 x 2 = 0.50 0

0.50 x 2 = 1.00 1
right/LSB

stop when fractional


part = 0 OR
continue until desired
number of decimal
places
22
Converting Decimal Fractions-to-Binary
23
Using Sum-of-weights
Binary weights
64 32 16 8 4 2 1 .5 .25 .125 .0625
95.6875 = 64 + 16 + 8 + 4 + 2 + 1 + .5 + .125 + .0625
=
1011111.1011
Repeated division by 2 yields the whole number while
repeated multiplication by 2 of the fraction yields the
binary fraction
95.6875
W hole Fraction
95
24 = 47 1
2 0.6875 x 2 = 1.3750 1
47
= 23 1
2
0.3750 x 2 = 0.75 0
23
= 11 1
2
0.75 x 2 = 1.50 1
11
= 5 1
2
5 0.50 x 2 = 1.00 1
= 2 1
2
2
= 1 0
2
95.6875 in decimal
1
= 0 1
W hole . Fraction
2
1011111 . 1011 in binary
2.8 Hexadecimal Number
25
System
 Most digital systems deal with groups of bits in even
powers of 2 such as 8, 16, 32, and 64 bits.
 Hexadecimal uses groups of 4 bits.
 Base 16
 16 possible symbols
 0-9 and A-F

 Allows for convenient handling of long binary


strings.
Hex-to-Decimal Conversion 2.8

26
 Convert from hex to decimal by multiplying each
hex digit by its positional weight.

 Example:

2 1 0
16316  1 (16 )  6  (16 )  3  (16 )
 1 256  6 16  3 1
 35510

Ronald Tocci/Neal Widmer/Gregory Moss Copyright ©2004 by Pearson Education, Inc.


Digital Systems: Principles and Applications, 9e Upper Saddle River, New Jersey 07458
All rights reserved.
Decimal-to-Hex Conversion 2.8

27
 Convert from decimal to hex by using the repeated
division method used for decimal to binary and
decimal to octal conversion.
 Divide the decimal number by 16
 The first remainder is the LSB and the last is the
MSB.
 Note, when done on a calculator a decimal remainder can be
multiplied by 16 to get the result. If the remainder is greater
than 9, the letters A through F are used.
Example 2.8

28

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

 Example of hex to binary conversion.

9F216 = 9 F 2
= 1001 1111 0010
= 1001111100102
Decimal-to-Hex
-to-
29

650 Right/LSB
= 40.625 x 16 = 10 = A
16
40 2 8 A
= 2.5 x 16 = 8
16
2
= 0.125 x 16 = 2
16
Left/M SB
done!
650 10 = 28A 16
Binary-to-Hex Conversion 2.8

30

 Convert from binary to hex by grouping bits in four


starting with the LSB.
 Each group is then converted to the hex equivalent
 Leading zeros can be added to the left of the MSB
to fill out the last group.
Example 2.8

31
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

 Example of binary to hex conversion.


(Note the addition of leading zeroes)

11101001102 = 0011 1010 0110


= 3 A 6
= 3A616
 Counting in hex requires a reset and carry after

reaching F.
Binary-to-Hex
32

1100101001010111 2
1100101001010111 2
12 10 5 7
C A 5 7
C A 57 16
Hex and Octal 2.8

33

 Hex and octal are useful forms of shorthand to


represent long strings of bits.
 Understanding the conversion process and
memorizing the 4 bit patterns for each hex digit
will prove valuable later.
2.9 Octal Number
34
 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

85 84 83 82 81 80
32768 4096 512 64 8 1
2.9
Octal Number
35  Binary-to-Octal
-to- Conversion
 (ex : 10101111101100102)

001 010 111 110 110 010


1 2 7 6 6 2
 Octal-to-Binary
-to- Conversion
 (ex : 1276628)

1 2 7 6 6 2
001 010 111 110 110 010
2.10 Binary Coded Decimal
36 (BCD)
BCD is a way to express each of the decimal digits
with a binary code.
 There are only 10 code groups in the BCD system

0 1 2 3 4 5 6 7 8 9

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

 Ex : 3510 = 0011 0101


2.11 Digital Codes and Parity

37

 There are other specialized codes used in digital


systems  e.g. Gray code, ASCII code
 Some codes are
 strictly numeric : e.g. BCD
 Alphanumeric – to represent numbers, letters,
symbols, instructions : e.g. ASCII
 Gray Code
 is not an arithmetic code
38  Only one bit changes from one code to the next in the
sequence
 Gray code can be any amounts of bits. + Penambahan dalam modulo 2

0 +0 = 0

 Below is example from Gray Code-to-Binary


-to- 0 +1 =1

1 +0 = 1
 Eg : 1110 (Gray Code) 1 +1 = 0

1 1 1 0

+ + +

1 0 1 1

= 10112
 Gray Code
 Below is example from Binary-to-Gray
-to- Code
39
 Eg : 11102

1 + 1 + 1 + +
0
Penambahan dalam modulo 2

0 +0 = 0

0 +1 =1

1 +0 = 1

1 0 0 1
1 +1 = 0

= 1001 (Kod Gray)


DECIMAL BINARY GRAY CODE
0 0000 0000
1 0001 0001
40
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
ASCII
41  American Standard Code for Information
Interchange (ASCII)
 It has 128 characters and symbols represented in

7-bit binary code


 Example :

 A = 10000012;
 a = 11000012
Kos ASCII : 10000012
ASCII Table
42 000 001 010 011 100 101 110 111

0000 NUL DLE SP 0 @ P ` p


0001 SOH DCI ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EOT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Symbol Binary Hexadecimal
2 0110010 32
43
ASCII example: 0 0110000 30
Space 0100000 20
P 1010000 50
20 PRINT A=“X”; R 1010010 52
I 1001001 49
N 1001110 4E
T 1010100 54
Space 0100000 20
A 1000001 41
= 0111101 3D
10000012 = 0100 00012 “ 0100010 22

4 18 X 1011000 3B
“ 0100010 22
; 0111011 3B
Parity
44
 Parity bit used for bit error detection
 Even parity (0) – total number of 1s even (genap)
 Odd parity (1) – total number of 1s odd (ganjil)

 Example: (even parity)

Code transmitted: 00101


1’s total even; parity bit = 0
Code received: 00001
1’s total odd; parity bit = 0  error
EVEN PARITY ODD PARITY

PARITY BCD PARITY BCD


45 BIT BIT
0 0000 1 0000
1 0001 0 0001
1 0010 0 0010
0 0011 1 0011
1 0100 0 0100
0 0101 1 0101
0 0110 1 0110

1 0111 0 0111
1 1000 0 1000
0 1001 1 1001
Try this. Fill in the appropriate parity bit.
46

Even Odd

1010 0 1

111000 1 0

101101 0 1

1000111001001 0 1

101101011111 1 0
Link
47

wps.prenhall.com/chet_floyd_digitalfun_8/0,5650,419682-,00.html
www.educypedia.be/electronics/digitalnumber.htm
48

END OF CHAPTER 2

You might also like