Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 Funded
Book Description
Title: Digital Electronics: An Introduction To Theory And Practice
Author: W. H. Gothmann
Publisher: Prentice Hall Of India Pvt. Ltd., New Delhi
Edition: 2
Year: 1994
ISBN: 81-203-0348-2
Scilab numbering policy used in this document and the relation to the
above book.
Exa Example (Solved example)
Eqn Equation (Particular equation of the above book)
AP Appendix to Example(Scilab Code that is an Appednix to a particular
Example of the above book)
For example, Exa 3.51 means solved example 3.51 of this book. Sec 2.3 means
a scilab code whose theory is explained in Section 2.3 of the book.
Contents
List of Scilab Codes
2 Number Systems
3 Binary Codes
42
4 Boolean Algebra
58
6 Combinational Logic
62
97
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10
2.11
2.12
2.13
2.14
2.15
2.16
2.17
2.18
2.19
2.20
2.21
2.22
2.23
2.24
2.25
2.26
2.27
2.28
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
7
7
8
8
8
8
9
9
10
10
11
11
12
12
13
13
14
14
14
14
15
15
16
16
17
17
18
18
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
2.29
2.30
2.31
2.32
2.33
2.34
2.35
2.36
2.37
2.38
2.39
2.40
2.41
2.42
2.43
2.44
2.45
2.46
2.47
2.48
2.49
2.50
2.51
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
3.10
3.11
4.1
4.2
4.3
4.4
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
19
19
20
20
21
22
22
23
24
25
26
26
27
28
28
29
29
30
32
33
34
36
38
42
44
46
47
48
49
50
51
52
54
55
58
58
59
60
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
4.5
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
6.10
6.11
6.12
6.13
6.14.a
6.14.b
6.14.c
6.14.d
6.15
6.16
6.17
6.18
6.19
6.20
6.24
6.25
6.26
6.27
6.28
6.29
6.30
11.1
11.2
11.3
11.4
11.5
11.6
11.7
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
61
62
62
63
64
64
65
66
67
68
69
70
72
74
75
75
76
76
77
79
83
86
87
88
89
91
93
93
94
94
95
97
97
98
99
100
101
102
Chapter 2
Number Systems
// Example 2 6//
8
2 // D e c i m a l t o b i n a r y c o n v e r s i o n //
3 a = dec2bin (43)
4 // B i n a r y e q u i v a l e n t o f t h e d e c i m a l number //
5 disp ( a )
6 // a n s w e r i n b i n a r y form //
// Example 2 8//
// B i n a r y a d d i t i o n //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s t h e a l r e a d y e x i s t i n g v a r i a b l e s //
x = bin2dec ( 1 0 1 1 )
y = bin2dec ( 110 )
// b i n a r y t o d e c i m a l c o n v e r s i o n //
z=x+y
// a d d i t i o n //
a = dec2bin ( z )
// d e c i m a l t o b i n a r y c o n v e r s i o n //
disp ( a d d i t i o n o f t h e 2 b i n a r y numbers i s :
disp ( a )
// a n s w e r i n b i n a r y form //
9
// Example 2 9//
// B i n a r y a d d i t i o n //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s t h e a l r e a d y e x i s t i n g v a r i a b l e s //
x = bin2dec ( 1 1 1 1 0 )
y = bin2dec ( 11 )
// b i n a r y t o d e c i m a l c o n v e r s i o n //
z=x+y
// a d d i t i o n //
a = dec2bin ( z )
// d e c i m a l t o b i n a r y c o n v e r s i o n //
disp ( a d d i t i o n o f t h e 2 b i n a r y numbers i s :
disp ( a )
// a n s w e r i n b i n a r y form //
// Example 2 10//
// B i n a r y S u b t r a c t i o n //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x = bin2dec ( 100 )
y = bin2dec ( 1 )
// b i n a r y t o d e c i m a l c o n v e r s i o n //
z =x - y
10
11 // s u b t r a c t i o n //
12 a = dec2bin ( z )
13 // d e c i m a l t o b i n a r y c o n v e r s i o n //
14 disp ( s u b t r a c t i o n o f two b i n a r y numbers i s : )
15 disp ( a )
16 // a n s w e r i n b i n a r y form //
// Example 2 11//
// B i n a r y m u l t i p l i c a t i o n //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x = bin2dec ( 1 0 1 1 )
y = bin2dec ( 101 )
// b i n a r y t o d e c i m a l c o n v e r s i o n //
z=x*y;
// m u l t i p l i c a t i o n //
a = dec2bin ( z )
// d e c i m a l t o b i n a r y c o n v e r s i o n //
disp ( m u l t i p l i c a t i o n o f two b i n a r y numbers i s :
disp ( a )
// a n s w e r i n b i n a r y form //
11
6
7
8
9
10
11
12
13
14
15
16
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x = bin2dec ( 1 1 0 1 0 )
y = bin2dec ( 1 1 0 1 1 )
// b i n a r y t o d e c i m a l c o n v e r s i o n //
z=x*y;
// m u l t i p l i c a t i o n //
a = dec2bin ( z )
// d e c i m a l t o b i n a r y c o n v e r s i o n //
disp ( m u l t i p l i c a t i o n o f two b i n a r y numbers i s :
disp ( a )
// a n s w e r i n b i n a r y form //
// Example 2 13//
// B i n a r y D i v i s i o n //
x = bin2dec ( 1 1 0 1 1 0 )
y = bin2dec ( 101 )
r = modulo (x , y )
// f i n d i n g t h e r e m a i n d e r //
z=x/y
q = floor ( z )
// f i n d i n g t h e q u o t i e n t //
quo = dec2bin ( q )
rem = dec2bin ( r )
// d e c i m a l t o b i n a r y c o n v e r s i o n s //
disp ( t h e q u o t i e n t i s : )
disp ( quo )
disp ( t h e r e m a i n d e r i s : )
disp ( rem )
// a n s w e r s i n b i n a r y form //
1 // Example 2 14//
2 // b i n a r y t o h e x a d e c i m a l
3 x = bin2dec ( 1 0 1 0 1 1 1 0 1 0 )
4 // d e c i m a l e q u i v a l e n t o f
5 a = dec2hex ( x )
6 // Hex e q u i v a l e n t o f t h e
7 disp ( a )
8 // a n s w e r i n h e x a d e c i m a l
c o n v e r s i o n //
t h e b i n a r y number //
d e c i m a l number //
form //
13
1 // Example 2 20//
2 // D e c i m a l t o h e x a d e c i m a l c o n v e r s i o n //
3 a = dec2hex (423)
4 // h e x a d e c i m a l e q u i v a l e n t o f t h e d e c i m a l number //
5 disp ( a )
6 // a n s w e r i n h e x a d e c i m a l form //
// Example 2 22//
// H e x a d e c i m a l a d d i t i o n //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x = hex2dec ( 1A8 )
y = hex2dec ( 67B )
// D e c i m a l c o n v e r s i o n o f t h e h e x a d e c i m a l numbers //
z=x+y
// a d d i t i o n //
a = dec2hex ( z )
// d e c i m a l t o h e x a d e c i m a l c o n v e r s i o n //
disp ( a d d i t i o n o f t h e 2 h e x a d e c i m a l numbers i s )
disp ( a )
15
16
// a n s w e r i n h e x a d e c i m a l form //
// Example 2 23//
// H e x a d e c i m a l a d d i t i o n //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x = hex2dec ( ACEF1 )
y = hex2dec ( 16B7D )
// D e c i m a l c o n v e r s i o n o f t h e h e x a d e c i m a l numbers //
z=x+y
// a d d i t i o n //
a = dec2hex ( z )
// d e c i m a l t o h e x a d e c i m a l c o n v e r s i o n //
disp ( a d d i t i o n o f t h e 2 h e x a d e c i m a l numbers i s )
disp ( a )
// a n s w e r i n h e x a d e c i m a l form //
// Example 2 24//
// H e x a d e c i m a l S u b t r a c t i o n //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x = hex2dec ( 1 2 7 3 )
y = hex2dec ( 3A8 )
// D e c i m a l c o n v e r s i o n o f t h e h e x a d e c i m a l numbers //
z =x - y
16
11 // a d d i t i o n //
12 a = dec2hex ( z )
13 // d e c i m a l t o h e x a d e c i m a l c o n v e r s i o n //
14 disp ( a d d i t i o n o f t h e 2 h e x a d e c i m a l numbers i s
15 disp ( a )
16 // a n s w e r i n h e x a d e c i m a l form //
17
5
6
7
8
9
10
11
12
13
14
15
16
17
r = modulo (x , y )
// f i n d i n g t h e r e m a i n d e r //
z=x/y
q = floor ( z )
// f i n d i n g t h e q u o t i e n t //
quo = dec2hex ( q )
rem = dec2hex ( r )
// d e c i m a l t o b i n a r y c o n v e r s i o n s //
disp ( t h e q u o t i e n t i s : )
disp ( quo )
disp ( t h e r e m a i n d e r i s : )
disp ( rem )
// a n s w e r s i n b i n a r y form //
18
7
8
disp ( a )
// a n s w e r i n o c t a l form //
// Example 2 30//
// 5 i n t w o s complement form //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x =2^8
// S m a l l e s t n i n e b i t number //
y =5
z =x - y
// s u b t r a c t i o n //
a = dec2bin ( z )
// b i n a r y c o n v e r s i o n o f t h e d e c i m a l number //
disp ( 5 i n t w o s complement form i s )
disp ( a )
// a n s w e r i n b i n a r y form //
19
// Example 2 31//
// 4 , 15 , 17 i n t w o s complement form //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x =2^12
// S m a l l e s t n i n e b i t number //
p =4
q =15
r =17
u =x - p
v =x - q
w =x - r
// s u b t r a c t i o n //
a = dec2bin ( u )
b = dec2bin ( v )
c = dec2bin ( w )
// b i n a r y c o n v e r s i o n o f t h e d e c i m a l number //
disp ( 4 i n t w o s complement form i s )
disp ( a )
disp ( 15 i n t w o s complement form i s )
disp ( b )
disp ( 17 i n t w o s complement form i s )
disp ( c )
// a n s w e r s i n b i n a r y form //
// Example 2 32//
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
r e p r e s e n t a t i o n ) //
9 y =1
10 z = x + y
11 // 1 i s added t o t h e complement //
12 a = dec2bin ( z )
13 // b i n a r y c o n v e r s i o n o f t h e d e c i m a l number //
14 disp ( 4 i n t w o s complement form i s : )
15 disp ( a )
16 // r e s u l t i s d i s p l a y e d //
21
r e p r e s e n t a t i o n ) //
9 y =1
10 z = x + y
11 // 1 i s added t o t h e complement //
12 a = dec2bin ( z )
13 // b i n a r y c o n v e r s i o n o f t h e d e c i m a l number //
14 disp ( 17 i n t w o s complement form i s : )
15 disp ( a )
16 // r e s u l t i s d i s p l a y e d //
// Example 2 35//
//4 i n two s complement by t h i r d method //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
a =00000100
c =0
z =0
22
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
for i =1: 8
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
end
for i =1: 8
if c >1 then
break
end
if x ( i ) ==1 then
for k = i +1: 8
x ( k ) = bitcmp ( x ( k ) ,1)
c = c +1
end
end
end
for i =1: 8
z = z + x ( i ) *10^( i -1)
end
disp ( 4 i n t w o s complement i s : )
disp ( z )
// a n s w e r i s d i s p l a y e d //
// Example 2 36//
// 17 i n two s complement by t h i r d method //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
a =00010001
c =0
z =0
for i =1: 8
23
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
end
for i =1: 8
if c >1 then
break
end
if x ( i ) ==1 then
for k = i +1: 8
x ( k ) = bitcmp ( x ( k ) ,1)
c = c +1
end
end
end
for i =1: 8
z = z + x ( i ) *10^( i -1)
end
disp ( 17 i n t w o s complement i s : )
disp ( z )
// a n s w e r i s d i s p l a y e d //
r e p r e s e n t a t i o n ) //
10 y =1
24
11 z = x + y
12 // 1 i s added t o t h e complement //
13 a = dec2bin ( z )
14 // b i n a r y c o n v e r s i o n o f t h e d e c i m a l number //
15 z = z *( -1)
16 disp ( t h e n e g a t i v e v a l u e t h a t 1 0 0 1 1 0 1 1 r e p r e s e n t s
17
18
is : )
disp ( z )
// r e s u l t i s d i s p l a y e d //
// Example 2 38//
// add 17 t o 30//
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s i t i n g v a r i a b l e s //
x = bitcmp (17 ,8)
y = bitcmp (30 ,8)
// complement o f t h e d e c i m a l numbers 17 and 3 0 / /
z =1
u=x+z
v=y+z
// 1 i s added t o t h e c o m p l e m e n t s //
w=u+v
a = dec2bin ( w )
// b i n a r y c o n v e r s i o n o f t h e d e c i m a l number //
disp ( b i n a r y form o f number o b t a i n e d by a d d i n g 17
t o 30 )
disp ( a )
// r e s u l t i s d i s p l a y e d //
disp ( t h e msb i s d i s c a r d e d , s o e i g h t b i t
r e p r e s e n t a t i o n i s t h e a n s w e r i n b i n a r y form )
a = dec2bin (w -(2^8) )
25
22
23
disp ( a )
// f i n a l r e s u l t i s d i s p l a y e d //
// Example 2 39//
// add 20 t o 2 6 / /
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x = bitcmp (20 ,8)
// f i n d s complement o f 2 9 / /
y =1
u=x+y
// 1 i s added t o t h e complement //
v =26
w=u+v
a = dec2bin ( w )
// b i n a r y c o n v e r s i o n o f t h e d e c i m a l number //
disp ( b i n a r y form o f t h e number o b t a i n e d by a d d i n g
20 t o 26 )
disp ( a )
// r e s u l t i s d i s p l a y e d //
disp ( t h e msb i s d i s c a r d e d , s o e i g h t b i t
r e p r e s e n t a t i o n i s t h e a n s w e r i n b i n a r y form )
a = dec2bin (w -(2^8) )
disp ( a )
// f i n a l r e s u l t i s d i s p l a y e d //
// Example 2 40//
26
// add 29 t o 1 4 / /
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
x = bitcmp (29 ,8)
// f i n d s complement o f 2 9 / /
y =1
u=x+y
// 1 i s added t o t h e complement //
v =14
w=u+v
a = dec2bin ( w )
// b i n a r y c o n v e r s i o n o f t h e d e c i m a l number //
disp ( b i n a r y form o f t h e number o b t a i n e d by a d d i n g
29 t o 14 )
17 disp ( a )
18 // r e s u l t i s d i s p l a y e d //
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
27
// Example 2 42//
// o n e s complement o f 13 by 2 nd method //
clc
// c l e a r s t h e window //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
a = bitcmp (0 ,8)
// d e c i m a l e q u i v a l e n t o f 1 1 1 1 1 1 1 1 / /
b =13
c =a - b
// s u b t r a c t i n g 13 from d e c i m a l e q u i v a l e n t o f
11111111//
z = dec2bin ( c )
disp ( o n e s complement o f 13 i s : )
disp ( z )
// r e s u l t i s d i s p l a y e d //
// Example 2 43//
// add 3 t o 2 i n one s complement u s i n g 4 b i t s //
clc
// c l e a r s t h e window //
clear
// c l e a r s a l l t h e e x i s t i n g v a r i a b l e s //
x = bitcmp (3 ,4)
y = bitcmp (2 ,4)
// complement o f t h e d e c i m a l number 2//
z = x + y +1
// c a r r y i s added //
28
12 a = dec2bin ( z )
13 // b i n a r y c o n v e r s i o n //
14 disp ( b i n a r y form o f t h e number o b t a i n e d by a d d i n g
3 t o 2 )
disp ( a )
// r e s u l t i s d i s p l a y e d //
disp ( msb i s d i s c a r d e d , 4 b i t r e p r e s e n t a t i o n i s t h e
a n s w e r i n b i n a r y form )
18 a = dec2bin (z -(2^4) )
19 disp ( a )
20 // F i n a l r e s u l t i s d i s p l a y e d //
15
16
17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Example 2 45//
// add 3 t o 2 i n one s complement u s i n g 8 b i t s //
clc
// c l e a r s t h e window //
clear
// c l e a r s a l l t h e e x i s t i n g v a r i a b l e s //
x =3
y = bitcmp (2 ,8)
// complement o f t h e d e c i m a l number 2//
z = x + y +1
// c a r r y i s added //
a = dec2bin ( z )
// b i n a r y c o n v e r s i o n //
disp ( b i n a r y form o f t h e number o b t a i n e d by a d d i n g 3
t o 2 )
disp ( a )
// r e s u l t i s d i s p l a y e d //
disp ( msb i s d i s c a r d e d , 8 b i t r e p r e s e n t a t i o n i s t h e
a n s w e r i n b i n a r y form )
a = dec2bin (z -(2^8) )
disp ( a )
// F i n a l r e s u l t i s d i s p l a y e d //
// Example 2 46//
// C o n v e r s i o n t o d e c i m a l //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
p =1
q =1
z =0
b =0
30
11 w =0
12 f =0
13 // i n i t i a l i s i n g //
14 // b i n=i n p u t ( e n t e r t h e b i n a r y number t o be c o n v e r t e d
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
t o i t s d e c i m a l form ) //
// a c c e p t i n g t h e i n p u t from t h e u s e r //
bin =1101.000101
d = modulo ( bin ,1)
// s e p a r a t i n g t h e d e c i m a l p a r t from t h e i n t e g e r p a r t
//
d = d *10^10
a = floor ( bin )
// r e m o v i n g t h e d e c i m a l p a r t //
while (a >0)
// l o o p t o e n t e r t h e b i n a r y b i t s o f t h e i n t e g e r p a r t
i n t o a m a t r i x //
r = modulo (a ,10)
b (1 , q ) = r
a = a /10
a = floor ( a )
q = q +1
end
for m =1: q -1
// m u l t i p l y i n g e a c h b i t o f t h e i n t e g e r p a r t w i t h i t s
c o r r e s p o n d i n g p o s i t i o n a l v a l u e and a d d i n g //
c =m -1
f = f + b (1 , m ) *(2^ c )
end
while (d >0)
// l o o p t o t a k e t h e b i t s o f t h e d e c i m a l p a r t i n t o a
m a t r i x //
e = modulo (d ,2)
w (1 , p ) = e
d = d /10
d = floor ( d )
p = p +1
end
for n =1: p -1
31
44
45
46
47
48
49
50
51
52
53
54
// m u l t i p l y i n g e a c h b i t w i t h i t s c o r r e s p o n d i n g
p o s i t i o n a l v a l u e and a d d i n g //
z = z + w (1 , n ) *(0.5) ^(11 - n )
end
z = z *10000
z = round ( z )
// r o u n d i n g o f f t o 4 d e c i m a l p l a c e s //
z = z /10000
x=f+z
disp ( t h e d e c i m a l e q u i v a l e n t o f t h e b i n a r y number i s
: )
disp ( x )
// r e s u l t i s d i s p l a y e d //
// Example 2 47//
// C o n v e r s i o n o f d e c i m a l t o b i n a r y //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
q =0
b =0
s =0
// i n i t i a l i s i n g //
// a=i n p u t ( e n t e r t h e d e c i m a l number t o be c o n v e r t e d
t o i t s b i n a r y form )
// t a k i n g i n p u t from t h e u s e r //
a =0.375
d = modulo (a ,1)
// s e p a r a t i n g t h e d e c i m a l p a r t from t h e i n t e g e r //
a = floor ( a )
// r e m o v i n g t h e d e c i m a l p a r t //
while (a >0)
32
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// i n t e g e r p a r t c o n v e r t e d t o e q u i v a l e n t b i n a r y form //
x = modulo (a ,2)
b = b +(10^ q ) * x
a = a /2
a = floor ( a )
q = q +1
end
for i =1: 10
// t a k i n g v a l u e s a f t e r t h e d e c i m a l p a r t and
c o n v e r t i n g t o e q u i v a l e n t b i n a r y form //
d = d *2
q = floor ( d )
s = s + q /(10^ i )
if d >=1 then
d =d -1
end
end
k=b+s
disp ( t h e d e c i m a l number i n b i n a r y form i s : )
disp ( k )
// r e s u l t i s d i s p l a y e d //
// Example 2 48//
// C o n v e r s i o n o f d e c i m a l t o b i n a r y //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
q =0
b =0
s =0
// i n i t i a l i s i n g //
// a=i n p u t ( e n t e r t h e d e c i m a l number t o be c o n v e r t e d
33
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
t o i t s b i n a r y form )
// t a k i n g i n p u t from t h e u s e r //
a =0.54545
d = modulo (a ,1)
// s e p a r a t i n g t h e d e c i m a l p a r t from t h e i n t e g e r //
a = floor ( a )
// r e m o v i n g t h e d e c i m a l p a r t //
while (a >0)
// i n t e g e r p a r t c o n v e r t e d t o e q u i v a l e n t b i n a r y form //
x = modulo (a ,2)
b = b +(10^ q ) * x
a = a /2
a = floor ( a )
q = q +1
end
for i =1: 10
// t a k i n g v a l u e s a f t e r t h e d e c i m a l p a r t and
c o n v e r t i n g t o e q u i v a l e n t b i n a r y form //
d = d *2
q = floor ( d )
s = s + q /(10^ i )
if d >=1 then
d =d -1
end
end
k=b+s
disp ( t h e d e c i m a l number i n b i n a r y form i s : )
disp ( k )
// r e s u l t i s d i s p l a y e d //
34
4 // c l e a r s t h e c o n s o l e //
5 clear
6 // c l e a r s a l l e x i s t i n g v a r i a b l e s //
7 q =0
8 b =0
9 s =0
10 // i n i t i a l i s i n g //
11 // a=i n p u t ( e n t e r t h e d e c i m a l number t o be c o n v e r t e d
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
t o i t s b i n a r y form )
// t a k i n g i n p u t from t h e u s e r //
a =38.21
d = modulo (a ,1)
// s e p a r a t i n g t h e d e c i m a l p a r t from t h e i n t e g e r //
a = floor ( a )
// r e m o v i n g t h e d e c i m a l p a r t //
while (a >0)
// i n t e g e r p a r t c o n v e r t e d t o e q u i v a l e n t b i n a r y form //
x = modulo (a ,2)
b = b +(10^ q ) * x
a = a /2
a = floor ( a )
q = q +1
end
for i =1: 10
// t a k i n g v a l u e s a f t e r t h e d e c i m a l p a r t and
c o n v e r t i n g t o e q u i v a l e n t b i n a r y form //
d = d *2
q = floor ( d )
s = s + q /(10^ i )
if d >=1 then
d =d -1
end
end
k=b+s
disp ( t h e i n t e g e r p a r t o f t h e b i n a r y form i s : )
disp ( b )
disp ( t h e f r a c t i o n a l p a r t o f t h e b i n a r y form i s : )
disp ( s )
35
40
// r e s u l t i s d i s p l a y e d //
// Example 2 50//
// a d d i t i o n o f b i n a r y numbers //
// t h i s program r e q u i r e s f u n c t i o n s b i n a r y 2 d e c i m a l . s c i
and d e c i m a l 2 b i n a r y . s c i //
clc
// c l e a r s t h e window //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
function x = binary2decimal ( bin )
p =1
q =1
z =0
b =0
w =0
f =0
// i n i t i a l i s i n g //
d = modulo ( bin ,1)
// s e p a r a t i n g t h e d e c i m a l p a r t from t h e i n t e g e r p a r t
//
d = d *10^10
a = floor ( bin )
// r e m o v i n g t h e d e c i m a l p a r t //
while (a >0)
// l o o p t o e n t e r t h e b i n a r y b i t s o f t h e i n t e g e r p a r t
i n t o a m a t r i x //
r = modulo (a ,10)
b (1 , q ) = r
a = a /10
a = floor ( a )
q = q +1
end
36
29 for m =1: q -1
30 // m u l t i p l y i n g e a c h b i t
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
b = b +(10^ q ) * x
a = a /2
a = floor ( a )
q = q +1
end
for i =1: 10
// t a k i n g v a l u e s a f t e r t h e d e c i m a l p a r t and
c o n v e r t i n g t o e q u i v a l e n t b i n a r y form //
d = d *2
q = floor ( d )
s = s + q /(10^ i )
if d >=1 then
d =d -1
end
end
y=b+s
endfunction
x = binary2decimal (11.011)
y = binary2decimal (10.001)
z=x+y
a = decimal2binary ( z )
disp ( t h e a d d i t i o n o f t h e b i n a r y numbers i s : )
disp ( a )
// r e s u l t i s d i s p l a y e d //
// Example 2 51//
// m u l t i p l i c a t i o n o f b i n a r y numbers //
// t h i s program r e q u i r e s f u n c t i o n s b i n a r y 2 d e c i m a l . s c i
and d e c i m a l 2 b i n a r y . s c i //
clc
// c l e a r s t h e window //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
38
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 for n =1: p -1
43 // m u l t i p l y i n g e a c h b i t w i t h
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
i t s corresponding
p o s i t i o n a l v a l u e and a d d i n g //
z = z + w (1 , n ) *(0.5) ^(11 - n )
end
z = z *10000
z = round ( z )
// r o u n d i n g o f f t o 4 d e c i m a l p l a c e s //
z = z /10000
x=f+z
endfunction
function y = decimal2binary ( a )
q =0
b =0
s =0
// i n i t i a l i s i n g //
d = modulo (a ,1)
// s e p a r a t i n g t h e d e c i m a l p a r t from t h e i n t e g e r //
a = floor ( a )
// r e m o v i n g t h e d e c i m a l p a r t //
while (a >0)
// i n t e g e r p a r t c o n v e r t e d t o e q u i v a l e n t b i n a r y form //
x = modulo (a ,2)
b = b +(10^ q ) * x
a = a /2
a = floor ( a )
q = q +1
end
for i =1: 10
// t a k i n g v a l u e s a f t e r t h e d e c i m a l p a r t and
c o n v e r t i n g t o e q u i v a l e n t b i n a r y form //
d = d *2
q = floor ( d )
s = s + q /(10^ i )
if d >=1 then
d =d -1
end
end
40
78
79
80
81
82
83
84
y=b+s
endfunction
x = binary2decimal (10.001)
y = binary2decimal (0.11)
z=x*y
a = decimal2binary ( z )
disp ( t h e m u l t i p l i c a t i o n o f t h e b i n a r y numbers i s :
)
85 disp ( a )
86 // r e s u l t i s d i s p l a y e d //
41
Chapter 3
Binary Codes
// Example 3 1//
//BCD a d d i t i o n //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
a =647
b =492
for i =1: 3
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
y ( i ) = modulo (b ,10)
b = b /10
b = floor ( b )
end
d = x (1) + y (1)
db = dec2bin ( d )
if d >9 then
db = dec2bin ( d +6)
db = dec2bin ( bin2dec ( db ) - bin2dec ( 1 0 0 0 0 ) )
42
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
end
e = x (2) + y (2)
eb = dec2bin ( e )
if d >9 then
eb = dec2bin ( e +1)
e = e +1
end
if e >9
eb = dec2bin ( e +6)
eb = dec2bin ( bin2dec ( eb ) - bin2dec ( 1 0 0 0 0 ) )
end
f = x (3) + y (3)
fb = dec2bin ( f )
if e >9 then
fb = dec2bin ( f +1)
f = f +1
end
if f >9
fb = dec2bin ( f +6)
fb = dec2bin ( bin2dec ( fb ) - bin2dec ( 1 0 0 0 0 ) )
dc (4) =1
end
dc (1) = bin2dec ( db )
dc (2) = bin2dec ( eb )
dc (3) = bin2dec ( fb )
z =0
for i =1: 4
z = z + dc ( i ) *(10^( i -1) )
end
disp ( z )
disp ( e q u i v a l e n t b i n a r y form )
p = strcat ( dec2bin ( dc (4) ,1) + dec2bin ( dc (3) ,4) + dec2bin (
dc (2) ,4) + dec2bin ( dc (1) ,4) )
54 disp ( p )
55 // a n s w e r i s d i s p l a y e d //
43
// Example 3 2//
//BCD a d d i t i o n //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
a =4318
b =7678
for i =1: 4
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
y ( i ) = modulo (b ,10)
b = b /10
b = floor ( b )
end
d = x (1) + y (1)
db = dec2bin ( d )
if d >9 then
db = dec2bin ( d +6)
db = dec2bin ( bin2dec ( db ) - bin2dec ( 1 0 0 0 0 ) )
end
e = x (2) + y (2)
eb = dec2bin ( e )
if d >9 then
eb = dec2bin ( e +1)
e = e +1
end
if e >9
eb = dec2bin ( e +6)
eb = dec2bin ( bin2dec ( eb ) - bin2dec ( 1 0 0 0 0 ) )
end
44
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
f = x (3) + y (3)
fb = dec2bin ( f )
if e >9 then
fb = dec2bin ( f +1)
f = f +1
end
if f >9
fb = dec2bin ( f +6)
fb = dec2bin ( bin2dec ( fb ) - bin2dec ( 1 0 0 0 0 ) )
end
g = x (4) + y (4)
gb = dec2bin ( g )
if f >9 then
gb = dec2bin ( g +1)
g = g +1
end
if g >9
gb = dec2bin ( g +6)
gb = dec2bin ( bin2dec ( gb ) - bin2dec ( 1 0 0 0 0 ) )
dc (5) =1
end
dc (1) = bin2dec ( db )
dc (2) = bin2dec ( eb )
dc (3) = bin2dec ( fb )
dc (4) = bin2dec ( gb )
z =0
for i =1: 5
z = z + dc ( i ) *(10^( i -1) )
end
disp ( z )
disp ( e q u i v a l e n t b i n a r y form )
p = strcat ( dec2bin ( dc (5) ,1) + dec2bin ( dc (4) ,4) + dec2bin (
dc (3) ,4) + dec2bin ( dc (2) ,4) + dec2bin ( dc (1) ,4) )
65 disp ( p )
66 // a n s w e r i s d i s p l a y e d //
45
// Example 3 3//
// add 3 and 2 i n E x c e s s 3 c o d e //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
n =3
m =2
z =0
a =0110
b =0101
ea = dec2bin ( n +3)
eb = dec2bin ( m +3)
for i =1: 4
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
y ( i ) = modulo (b ,10)
b = b /10
b = floor ( b )
end
for i =1: 4
g ( i ) = bitand ( x ( i ) ,y ( i ) )
p ( i ) = bitor ( x ( i ) ,y ( i ) )
end
c (1) =0
for i =1: 4
c ( i +1) = bitor ( g ( i ) , bitand ( p ( i ) ,c ( i ) ) )
end
if c (5) ==1 then
z = dec2bin ( bin2dec ( ea ) + bin2dec ( eb ) +3)
end
46
addition )
disp ( z )
disp ( e q u i v a l e n t d e c i m a l number )
disp ( m + n )
// r e s u l t i s d i s p l a y e d //
// Example 3 4//
// add 6 and 8 i n E x c e s s 3 c o d e //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
n =6
m =8
a =1001
b =1011
ea = dec2bin ( n +3)
eb = dec2bin ( m +3)
for i =1: 4
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
y ( i ) = modulo (b ,10)
b = b /10
b = floor ( b )
end
for i =1: 4
g ( i ) = bitand ( x ( i ) ,y ( i ) )
p ( i ) = bitor ( x ( i ) ,y ( i ) )
47
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
end
c (1) =0
for i =1: 4
c ( i +1) = bitor ( g ( i ) , bitand ( p ( i ) ,c ( i ) ) )
end
if c (5) ==1 then
z = dec2bin ( bin2dec ( ea ) + bin2dec ( eb ) +3)
end
if c (5) ==0 then
z = dec2bin ( bin2dec ( ea ) + bin2dec ( eb ) -3)
end
disp ( e q u i v a l e n t b i n a r y number a f t e r e x c e s s 3
addition )
disp ( z )
disp ( e q u i v a l e n t d e c i m a l number )
disp ( m + n )
// r e s u l t i s d i s p l a y e d //
// Example 3 5//
// b i n a r y t o g r a y c o d e //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
a =1011
for i =1: 4
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
end
y (4) = x (4)
k =3
while (k >0)
48
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Example 3 6//
// b i n a r y t o g r a y c o d e //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
a =1001011
for i =1: 7
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
end
y (7) = x (7)
k =6
while (k >0)
if bitand ( x ( k +1) ,x ( k ) ) ==1 then
y ( k ) = bitcmp (1 ,1)
49
18
19
20
21
22
23
24
25
26
27
28
29
30
else
y ( k ) = bitor ( x ( k +1) ,x ( k ) )
end
k =k -1
end
// d i s p l a y //
z =0
for i =1: 7
z = z + y ( i ) *(10^( i -1) )
end
disp ( e q u i v a l e n t g r a y c o d e )
disp ( z )
// e q u i v a l e n t g r a y c o d e i s d i s p l a y e d //
// Example 3 7//
// g r a y c o d e t o b i n a r y //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
a =1011
for i =1: 4
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
end
y (4) = x (4)
k =3
while (k >0)
if bitand ( y ( k +1) ,x ( k ) ) ==1 then
y ( k ) = bitcmp (1 ,1)
else
y ( k ) = bitor ( y ( k +1) ,x ( k ) )
50
20
21
22
23
24
25
26
27
28
29
end
k =k -1
end
z =0
for i =1: 4
z = z + y ( i ) *(10^( i -1) )
end
disp ( e q u i v a l e n t b i n a r y c o d e )
disp ( z )
// e q u i v a l e n t b i n a r y c o d e i s d i s p l a y e d //
// Example 3 8//
// g r a y c o d e t o b i n a r y //
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
a =1001011
for i =1: 7
x ( i ) = modulo (a ,10)
a = a /10
a = floor ( a )
end
y (7) = x (7)
k =6
while (k >0)
if bitand ( y ( k +1) ,x ( k ) ) ==1 then
y ( k ) = bitcmp (1 ,1)
else
y ( k ) = bitor ( y ( k +1) ,x ( k ) )
end
k =k -1
end
51
23 z =0
24 for i =1: 7
25
z = z + y ( i ) *(10^( i -1) )
26 end
27 disp ( e q u i v a l e n t b i n a r y c o d e : )
28 disp ( z )
29 // e q u i v a l e n t b i n a r y c o d e i s d i s p l a y e d //
// Example 3 9//
// Hamming c o d e //
clc
// c l e a r s t h e command window //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
z =1011
// i n p u t //
a =0; b =0; c =0; d =0;
// t a k i n g t h e i n p u t //
for i =1:7
x ( i ) =0
if i ==3 then
x ( i ) =1
end
if i ==5 then
x ( i ) =1
end
if i ==7 then
x ( i ) =1
end
end
// e s t a b l i s h i n g e v e n p a r i t y a t p o s i t i o n s 1 , 3 , 5 , 7 / /
for i =1: 7
if x ( i ) ==1 then
52
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
a = a +1
end
end
d = modulo (a ,2)
if ( d ==1) then
x (1) =1
end
// e s t a b l i s h i n g e v e n p a r i t y a t p o s i t i o n s 2 , 3 , 6 , 7 / /
for i =2: 7
if ( i ==5) then
continue
end
if ( x ( i ) ==1) then
b = b +1
end
end
d = modulo (b ,2)
if ( d ==1) then
x (2) =1
end
// e s t a b l i s h i n g e v e n p a r i t y a t p o s i t i o n s 4 , 5 , 6 , 7 / /
for i =5:7
if ( x ( i ) ==1) then
c = c +1
end
end
d = modulo (c ,2)
if ( d ==1) then
x (4) =1
end
// d i s p l a y i n g t h e r e s u l t //
disp ( t h e hamming c o d e f o r t h i s d a t a i s g i v e n a s )
for i =1:7
disp ( x ( i ) )
end
53
// Example 3 10//
// Hamming c o d e //
clc
// c l e a r s t h e command window //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
z =0101
// i n p u t //
a =0; b =0; c =0; d =0;
// t a k i n g t h e i n p u t //
for i =1:7
x ( i ) =0
if i ==3 then
x ( i ) =1
end
if i ==6 then
x ( i ) =1
end
end
// e s t a b l i s h i n g e v e n p a r i t y a t p o s i t i o n s 1 , 3 , 5 , 7 / /
for i =1: 7
if i ==6 then
continue
end
if x ( i ) ==1 then
a = a +1
end
end
d = modulo (a ,2)
if ( d ==1) then
x (1) =1
end
54
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// e s t a b l i s h i n g e v e n p a r i t y a t p o s i t i o n s 2 , 3 , 6 , 7 / /
for i =2: 7
if x ( i ) ==1 then
b = b +1
end
end
d = modulo (b ,2)
if ( d ==1) then
x (2) =1
end
// e s t a b l i s h i n g e v e n p a r i t y a t p o s i t i o n s 4 , 5 , 6 , 7 / /
for i =5:7
if ( x ( i ) ==1) then
c = c +1
end
end
d = modulo (c ,2)
if ( d ==1) then
x (4) =1
end
// d i s p l a y i n g t h e r e s u l t //
disp ( t h e hamming c o d e f o r t h i s d a t a i s g i v e n a s )
for i =1:7
disp ( x ( i ) )
end
55
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// i n c o r r e c t c o d e t a k e n a s i n p u t //
a =0; b =0; c =0; d =0;
// t a k i n g t h e i n p u t i n an a r r a y //
for i =1: 7
x ( i ) =1
if i ==2 then
x ( i ) =0
end
end
// c h e c k i n g f o r 4 , 5 , 6 , 7 e v e n p a r i t y //
for i =4: 7
if x ( i ) ==1 then
a = a +1
end
end
d = modulo (a ,2)
if d ==1 then
disp ( wrong e n t r y f o r 4 , 5 , 6 , 7 )
x (4) =1
else
disp ( c o r r e c t e n t r y f o r 4 , 5 , 6 , 7 )
end
// c h e c k i n g f o r 2 , 3 , 6 , 7 e v e n p a r i t y //
for i =2: 7
if i ==4 then
continue
end
if i ==5 then
continue
end
if x ( i ) ==1 then
a = a +1
end
end
d = modulo (a ,2)
if d ==1 then
disp ( wrong e n t r y f o r 2 , 3 , 6 , 7 )
x (2) =1
56
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
else
disp ( c o r r e c t e n t r y f o r 2 , 3 , 6 , 7 )
end
// c h e c k i n g f o r 1 , 3 , 5 , 7 e v e n p a r i t y //
for i =1: 7
if i ==2 then
continue
end
if i ==4 then
continue
end
if i ==6 then
continue
end
if x ( i ) ==1 then
a = a +1
end
end
d = modulo (a ,2)
if d ==1 then
disp ( c o r r e c t e n t r y f o r 1 , 3 , 5 , 7 )
x (1) =1
else
disp ( wrong e n t r y f o r 1 , 3 , 5 , 7 )
end
disp ( T h e r e f o r e , b i t 2 i s i n e r r o r and t h e c o r r e c t e d
code i s : )
for i =1: 7
disp ( x ( i ) )
end
// c o r r e c t c o d e i s d i s p l a y e d //
57
Chapter 4
Boolean Algebra
1 // Example 4 2//
2 // R e d u c i n g an e x p r e s s i o n //
3 clc
4 // c l e a r s t h e c o n s o l e //
5 clear
6 // c l e a r s a l l e x i s t i n g v a r i a b l e s //
7 // t h e g i v e n e x p r e s s i o n i s a s f o l l o w s //
8 disp ( Given E x p r e s s i o n A+B(C+(DE) ) )
9 disp ( a p p l y i n g DeMorgan t h e o r e m )
10 disp ( r e d u c e d e x p r e s s i o n : )
11 disp ( A+B(C+D +E ) )
12 disp ( A p p l y i n g DeMorgan t h e o r e m a g a i n )
13 disp ( A+B(C DE) )
14 disp ( T h e r e f o r e f i n a l r e d u c e d e x p r e s s i o n i s
15 disp ( A+BC DE )
16 // f i n a l e x p r e s s i o n d i s p l a y e d //
59
17
18
19
20
21
22
23
disp ( (A+A +B ) )
// by law 1 3 / /
disp ( (1+B ) )
// by law 1 1 / /
disp ( 1 )
disp ( 0 )
// f i n a l r e d u c e d e x p r e s s i o n i s d i s p l a y e d /
60
)
disp ( f a c t o r i s e )
disp ( ( (A(B +BC) ) +A(B+AB ) ) )
// r e d u c e u s i n g l a w s 18 and 2 0 / /
disp ( ( (A(B +C) ) +A(B+A) ) )
disp ( m u l t i p l y )
disp ( ( (AB +AC) +AA+AB) )
// r e d u c e u s i n g l a w s 7 , 8 , 1 1 , 1 8 / /
disp ( ( (AB +AC) +A) )
disp ( d e m o r g a n i z e )
disp ( ( (A +B) (A +C )+A) )
disp ( m u l t i p l y )
disp ( (A A +A C +A B+BC +A) )
// Reduce u s i n g l a w s 1 8 , 8 / /
disp ( (A (1+C +B)+BC +A) )
// r e d u c e u s i n g law 1 8 , 7 , 1 1 / /
disp ( 1 )
disp ( 0 )
// f i n a l r e d u c e d e x p r e s s i o n i s d i s p l a y e d //
61
Chapter 6
Combinational Logic
62
1 // Example 6 2//
2 // f i n d m i n t e r m s f o r A+BC//
3 clc
4 // c l e a r s t h e c o n s o l e //
5 clear
6 // c l e a r s a l l e x i s t i n g v a r i a b l e s //
7 // c o n v e r s i o n t o m i n t e r m s //
8 disp ( Given e x p r e s s i o n A+BC )
9 disp ( on s o l v i n g )
10 disp ( A(B+B ) (C+C )+BC(A+A )
)
11 disp ( (AB+AB ) (C+C )+BCA+BCA
)
12 disp ( m u l t i p l y i n g )
13 disp ( C AB+AB C+AB C+AB C +BCA+BCA
14 // f i n a l r e s u l t i s d i s p l a y e d //
63
10 disp ( a f t e r s u b s t i t u t i o n )
11 disp ( 1 0 0 0 )
12 a = bin2dec ( 1 0 0 0 )
13 disp ( t h e d e c i m a l e q u i v a l e n t o f 1 0 0 0 i s : )
14 disp ( a )
15 disp ( T h e r e f o r e d e c i m a l s u b s c r i p t o f m i s 8 )
16 disp ( AB C D = m8
)
17 // r e s u l t i s d i s p l a y e d //
12 a = bin2dec ( 0 0 1 0 )
13 disp ( t h e r e f o r e t h e d e c i m a l e q u i v a l e n t o f 0 0 1 0 i s : )
14 disp ( a )
15 disp ( T h e r e f o r e d e c i m a l s u b s c r i p t o f m i s 2 )
16 disp ( W X YZ = m2
)
17 // r e s u l t i s d i s p l a y e d //
// Example 6 6//
//map C=A B +AB / /
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
// Mapping t h e e x p r e s s i o n //
disp (
B B )
disp ( A 1
0 )
disp ( A
1
0
)
disp ( From t h e map , h i g h o u t p u t s f o r 0 and 2 )
a =[0 0 ; 1 0]
disp ( a )
for i =1: 2
if a (i ,1) ==1 then
b (i ,1) = A
else
b (i ,1) = A
end
if a (i ,2) ==1 then
b (i ,2) = B
else
b (i ,2) = B
end
end
m = strcat ([ b (1 ,1) ,b (1 ,2) ])
65
t a b l e and
map )
29 x = strcat ([ m + ,n ]) ;
30 disp ( x )
31 // E x p r e s s i o n i s d i s p l a y e d //
66
27
else
28
b (i ,3) = C
29
end
30 end
31 disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h
32
33
34
35
36
37
t a b l e and
map )
l = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ])
m = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ])
n = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ])
x = strcat ([ l + ,m + ,n ])
disp ( x )
// E x p r e s s i o n i s d i s p l a y e d //
A
)
disp (
D E D E DE DE
E DE DE )
disp ( B C
0
0
0 0
0
0 0
)
disp ( BC
0
0
0 0
1
0 0
)
disp ( BC
0
0
0 0
1
1 1
)
disp ( BC
0
1
0 0
0
0 0
)
67
D E D
0
1
0
0
(0 ,1 ,3 ,5 ,7 ,10 ,11 ,21 ,22 ,23 ,24 ,26 ,30 ,32 ,34 ,35 ,40 ,41 ,46 ,47 ,50 ,51 ,52 ,6
)
9 disp (
B
B
)
10 disp (
E F E F EF EF
E F
E F EF EF )
11 disp (
C D
1
1
1 0
0
0
0 0
)
12 disp ( A CD
0
1
1 0
0
1
1 1
)
13 disp (
CD
0
0
0 0
0
0
0 1
)
14 disp (
CD
0
0
1 1
1
0
0 1
)
15 disp (
16
)
disp (
0
17 disp ( A
0
C D
1 1
CD
0 0
1
)
0
)
68
CD
0
0
1 1
1
1
0 0
)
19 disp (
CD
1
1
0 0
0
0
0 0
)
20 disp ( From t h e map , h i g h o u t p u t s f o r
0 ,1 ,3 ,5 ,7 ,10 ,11 ,21 ,22 ,23 ,24 ,26 ,30 ,32 ,34 ,35 ,40 ,41 ,46 ,47 ,50 ,51 ,52 ,60
)
21 // T h e r e f o r e t h e kmap i s d i s p l a y e d //
18
disp (
69
25
b (i ,2) = X
26
end
27
if a (i ,3) ==1 then
28
b (i ,3) = Y
29
else
30
b (i ,3) = Y
31
end
32
if a (i ,4) ==1 then
33
b (i ,4) = Z
34
else
35
b (i ,4) = Z
36
end
37 end
38 disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h
39
40
41
42
43
44
45
map )
l = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ,b (1 ,4) ])
m = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ,b (2 ,4) ])
n = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ,b (3 ,4) ])
o = strcat ([ b (4 ,1) ,b (4 ,2) ,b (4 ,3) ,b (4 ,4) ])
x = strcat ([ l + ,m + ,n + ,o ])
disp ( x )
// E x p r e s s i o n i s d i s p l a y e d //
70
t a b l e and
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
disp ( AB
0
1
1 0 )
disp ( AB
0
0
0 0 )
disp ( From t h e map , h i g h o u t p u t s f o r
0 ,1 ,2 ,3 ,6 ,7 ,13 ,15 )
// g i v e n l o g i c e q u a t i o n //
a =[0 0 0 0;0 0 0 1;0 0 1 0;0 0 1 1 ;0 1
1;1 1 0 1;1 1 1 1]
disp ( a )
for i =1: 8
if a (i ,1) ==1 then
b (i ,1) = A
else
b (i ,1) = A
end
if a (i ,2) ==1 then
b (i ,2) = B
else
b (i ,2) = B
end
if a (i ,3) ==1 then
b (i ,3) = C
else
b (i ,3) = C
end
if a (i ,4) ==1 then
b (i ,4) = D
else
b (i ,4) = D
end
end
disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h
map )
x1 = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ,b (1 ,4)
x2 = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ,b (2 ,4)
x3 = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ,b (3 ,4)
x4 = strcat ([ b (4 ,1) ,b (4 ,2) ,b (4 ,3) ,b (4 ,4)
x5 = strcat ([ b (5 ,1) ,b (5 ,2) ,b (5 ,3) ,b (5 ,4)
x6 = strcat ([ b (6 ,1) ,b (6 ,2) ,b (6 ,3) ,b (6 ,4)
71
1 0;0 1 1
t a b l e and
])
])
])
])
])
])
)
disp ( A B +A C+ABD )
23
if a (i ,2) ==1 then
24
b (i ,2) = B
25
else
26
b (i ,2) = B
27
end
28
if a (i ,3) ==1 then
29
b (i ,3) = C
30
else
31
b (i ,3) = C
32
end
33
if a (i ,4) ==1 then
34
b (i ,4) = D
35
else
36
b (i ,4) = D
37
end
38 end
39 disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
t a b l e and
map )
x1 = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ,b (1 ,4) ])
x2 = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ,b (2 ,4) ])
x3 = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ,b (3 ,4) ])
x4 = strcat ([ b (4 ,1) ,b (4 ,2) ,b (4 ,3) ,b (4 ,4) ])
x5 = strcat ([ b (5 ,1) ,b (5 ,2) ,b (5 ,3) ,b (5 ,4) ])
x6 = strcat ([ b (6 ,1) ,b (6 ,2) ,b (6 ,3) ,b (6 ,4) ])
x7 = strcat ([ b (7 ,1) ,b (7 ,2) ,b (7 ,3) ,b (7 ,4) ])
x8 = strcat ([ b (8 ,1) ,b (8 ,2) ,b (8 ,3) ,b (8 ,4) ])
x9 = strcat ([ b (9 ,1) ,b (9 ,2) ,b (9 ,3) ,b (9 ,4) ])
x10 = strcat ([ b (10 ,1) ,b (10 ,2) ,b (10 ,3) ,b (10 ,4) ])
x =([ x1 + , x2 + , x3 + , x4 + , x5 + , x6 + , x7 + , x8 + ,
x9 + , x10 ])
disp ( x )
// E x p r e s s i o n i s d i s p l a y e d //
disp ( now r e d u c i n g e x p r e s s i o n u s i n g b o o l e a n a l g e b r a
)
disp ( A B C+BD+AB+AD )
73
0 , 2 , 3 , 4 , 5 and
7 )
a =[0 0 0 ; 0 1 0 ; 0 1 1 ; 1 0 0 ; 1 0 1 ;1 1 1]
disp ( a )
for i =1: 6
if a (i ,1) ==1 then
b (i ,1) = A
else
b (i ,1) = A
end
if a (i ,2) ==1 then
b (i ,2) = B
else
b (i ,2) = B
end
if a (i ,3) ==1 then
b (i ,3) = C
else
b (i ,3) = C
end
end
disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h t a b l e and
74
32
33
34
35
36
37
38
39
40
41
42
map )
x1 = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ])
x2 = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ])
x3 = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ])
x4 = strcat ([ b (4 ,1) ,b (4 ,2) ,b (4 ,3) ])
x5 = strcat ([ b (5 ,1) ,b (5 ,2) ,b (5 ,3) ])
x6 = strcat ([ b (6 ,1) ,b (6 ,2) ,b (6 ,3) ])
x =([ x1 + , x2 + , x3 + , x4 + , x5 + , x6 ])
disp ( x )
// E x p r e s s i o n i s d i s p l a y e d //
disp ( a p p l y i n g l a w s o f b o o l e a n a l g e b r a )
disp ( AC+A B+B C )
// e x a m p l e 614b //
// Number o f i n p u t s r e q u i r e d //
75
3 clc
4 // c l e a r s t h e window //
5 clear
6 // c l e a r s a l l e x i s t i n g v a r i a b l e s //
7 disp ( X=LM+N PQ+LM PQ )
8 disp ( c o u n t AND i n p u t s )
9 disp ( 2+3+4=9 )
10 disp ( c o u n t OR i n p u t s )
11 disp ( 1+1+1=3 )
12 disp ( t h e r e f o r e t o t a l i n p u t s =12 )
13 // r e s u l t i s d i s p l a y e d //
r e q u i r e d //
76
4
5
6
7
8
9
10
11
12
13
// c l e a r s t h e window //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
disp ( (A+B +C) (A +D) (B+D ) )
disp ( c o u n t OR i n p u t s )
disp ( 3+2+2=7 )
disp ( c o u n t AND i n p u t s )
disp ( 1+1+1=3 )
disp ( t h e r e f o r e t o t a l i n p u t s =10 )
// r e s u l t i s d i s p l a y e d //
(2 ,3 ,6 ,7 ,9 ,10 ,12 ,13 ,14 ,16 ,18 ,22 ,26 ,28 ,29 ,30) )
disp (
A
A
)
disp (
D E D E DE DE
D E D
E DE DE )
disp ( B C
0
0
1 1
1
0
0 1
)
disp ( BC
0
0
1 1
0
0
0 1
)
disp ( BC
1
1
0 1
1
1
0 1
)
disp ( BC
0
1
0 1
0
0
0 1
)
disp ( From t h e map , h i g h o u t p u t s f o r
77
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
2 ,3 ,6 ,7 ,9 ,10 ,12 ,13 ,14 ,16 ,18 ,22 ,26 ,28 ,29 ,30 )
// T h e r e f o r e t h e kmap i s d i s p l a y e d //
a =[0 0 0 1 0;0 0 0 1 1;0 0 1 1 0;0 0 1 1 1;0 1 0 0
1;0 1 0 1 0;0 1 1 0 0;0 1 1 0 1;0 1 1 1 0;1 0 0 0
0;1 0 0 1 0;1 0 1 1 0;1 1 0 1 0;1 1 1 0 0;1 1 1
0 1;1 1 1 1 0]
disp ( a )
for i =1: 16
if a (i ,1) ==1 then
b (i ,1) = A
else
b (i ,1) = A
end
if a (i ,2) ==1 then
b (i ,2) = B
else
b (i ,2) = B
end
if a (i ,3) ==1 then
b (i ,3) = C
else
b (i ,3) = C
end
if a (i ,4) ==1 then
b (i ,4) = D
else
b (i ,4) = D
end
if a (i ,5) ==1 then
b (i ,5) = E
else
b (i ,5) = E
end
end
disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h t a b l e and
map )
x1 = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ,b (1 ,4) ,b (1 ,5) ])
x2 = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ,b (2 ,4) ,b (2 ,5) ])
78
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
79
5
6
7
8
9
10
11
12
13
14
15
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
// Mapping t h e e x p r e s s i o n //
disp ( Y=m
(0 ,2 ,4 ,8 ,10 ,13 ,15 ,16 ,18 ,20 ,23 ,24 ,26 ,32 ,34 ,40 ,42 ,45 ,47 ,48 ,50 ,56 ,57
)
disp (
B
B
)
disp (
E F E F EF EF
E F
E F EF EF )
disp (
C D
1
0
0 1
1
0
0 1
)
disp ( A CD
1
0
0 0
1
0
1 0
)
disp (
CD
0
1
1 0
0
0
0 0
)
disp (
CD
1
0
0 1
1
0
0 1
)
disp (
)
16 disp (
17
18
19
20
21
22
C D
1
0
0 1
1
0
0 1
)
disp ( A
CD
0
0
0 0
0
0
0 0
)
disp (
CD
0
1
1 0
1
1
0 0
)
disp (
CD
1
0
0 1
1
1
0 1
)
disp ( From t h e map , h i g h o u t p u t s f o r
0 ,2 ,4 ,8 ,10 ,13 ,15 ,16 ,18 ,20 ,23 ,24 ,26 ,32 ,34 ,40 ,42 ,45 ,47 ,48 ,50 ,56 ,57 ,5
)
// T h e r e f o r e t h e kmap i s d i s p l a y e d //
a =[0 0 0 0 0 0;0 0 0 0 1 0;0 0 0 1 0 0;0 0 1 0 0 0;0
0 1 0 1 0;0 0 1 1 0 1;0 0 1 1 1 1;0 1 0 0 0 0;0
1 0 0 1 0;0 1 0 1 0 0;0 1 0 1 1 1;0 1 1 0 0 0;0 1
1 0 1 0;1 0 0 0 0 0;1 0 0 0 1 0;1 0 1 0 0 0;1 0
1 0 1 0;1 0 1 1 0 1;1 0 1 1 1 1;1 1 0 0 0 0;1 1 0
80
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(2 ,6) ])
58 x3 = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ,b (3 ,4) ,b (3 ,5) ,b
(3 ,6) ])
59 x4 = strcat ([ b (4 ,1) ,b (4 ,2) ,b (4 ,3) ,b (4 ,4) ,b (4 ,5) ,b
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(4 ,6) ])
x5 = strcat ([ b (5 ,1) ,b (5 ,2) ,b (5 ,3) ,b (5 ,4) ,b (5 ,5) ,b
(5 ,6) ])
x6 = strcat ([ b (6 ,1) ,b (6 ,2) ,b (6 ,3) ,b (6 ,4) ,b (6 ,5) ,b
(6 ,6) ])
x7 = strcat ([ b (7 ,1) ,b (7 ,2) ,b (7 ,3) ,b (7 ,4) ,b (7 ,5) ,b
(7 ,6) ])
x8 = strcat ([ b (8 ,1) ,b (8 ,2) ,b (8 ,3) ,b (8 ,4) ,b (8 ,5) ,b
(8 ,6) ])
x9 = strcat ([ b (9 ,1) ,b (9 ,2) ,b (9 ,3) ,b (9 ,4) ,b (9 ,5) ,b
(9 ,6) ])
x10 = strcat ([ b (10 ,1) ,b (10 ,2) ,b (10 ,3) ,b (10 ,4) ,b (10 ,5)
,b (10 ,6) ])
x11 = strcat ([ b (11 ,1) ,b (11 ,2) ,b (11 ,3) ,b (11 ,4) ,b (11 ,5)
,b (11 ,6) ])
x12 = strcat ([ b (12 ,1) ,b (12 ,2) ,b (12 ,3) ,b (12 ,4) ,b (12 ,5)
,b (12 ,6) ])
x13 = strcat ([ b (13 ,1) ,b (13 ,2) ,b (13 ,3) ,b (13 ,4) ,b (13 ,5)
,b (13 ,6) ])
x14 = strcat ([ b (14 ,1) ,b (14 ,2) ,b (14 ,3) ,b (14 ,4) ,b (14 ,5)
,b (14 ,6) ])
x15 = strcat ([ b (15 ,1) ,b (15 ,2) ,b (15 ,3) ,b (15 ,4) ,b (15 ,5)
,b (15 ,6) ])
x16 = strcat ([ b (16 ,1) ,b (16 ,2) ,b (16 ,3) ,b (16 ,4) ,b (16 ,5)
,b (16 ,6) ])
x17 = strcat ([ b (17 ,1) ,b (17 ,2) ,b (17 ,3) ,b (17 ,4) ,b (17 ,5)
,b (17 ,6) ])
x18 = strcat ([ b (18 ,1) ,b (18 ,2) ,b (18 ,3) ,b (18 ,4) ,b (18 ,5)
,b (18 ,6) ])
x19 = strcat ([ b (19 ,1) ,b (19 ,2) ,b (19 ,3) ,b (19 ,4) ,b (19 ,5)
,b (19 ,6) ])
x20 = strcat ([ b (20 ,1) ,b (20 ,2) ,b (20 ,3) ,b (20 ,4) ,b (20 ,5)
,b (20 ,6) ])
82
76 x21 = strcat ([ b (21 ,1) ,b (21 ,2) ,b (21 ,3) ,b (21 ,4) ,b (21 ,5)
,b (21 ,6) ])
77 x22 = strcat ([ b (22 ,1) ,b (22 ,2) ,b (22 ,3) ,b (22 ,4) ,b (22 ,5)
,b (22 ,6) ])
78 x23 = strcat ([ b (23 ,1) ,b (23 ,2) ,b (23 ,3) ,b (23 ,4) ,b (23 ,5)
79
80
81
82
83
84
85
86
,b (23 ,6) ])
x24 = strcat ([ b (24 ,1) ,b (24 ,2) ,b (24 ,3) ,b (24 ,4) ,b (24 ,5)
,b (24 ,6) ])
x25 = strcat ([ b (25 ,1) ,b (25 ,2) ,b (25 ,3) ,b (25 ,4) ,b (25 ,5)
,b (25 ,6) ])
x26 = strcat ([ b (26 ,1) ,b (26 ,2) ,b (26 ,3) ,b (26 ,4) ,b (26 ,5)
,b (26 ,6) ])
x =([ x1 + , x2 + , x3 + , x4 + , x5 + , x6 + , x7 + , x8 + ,
x9 + , x10 + , x11 + , x12 + , x13 + , x14 + , x15 + ,
x16 + , x17 + , x18 + , x19 + , x20 + , x21 + , x22 + ,
x23 + , x24 + , x25 + , x26 ])
disp ( x )
disp ( Reduced e x p r e s s i o n )
disp ( A BC DEF+A C E F +B CDF+ABCE +D F )
// E x p r e s s i o n i s d i s p l a y e d //
// Example 6 17//
// r e d u c e e x p r e s s i o n u s i n g kmap by b o t h POS and SOP
//
clc
// c l e a r s t h e window //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
// Mapping t h e e x p r e s s i o n //
disp (
C D C D CD CD )
disp ( A B
1
1
1 0 )
disp ( AB
0
0
1 1 )
83
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
disp ( AB
0
1
1 0 )
disp ( AB
1
1
0 0 )
disp ( From t h e map , h i g h o u t p u t s f o r
0 ,1 ,3 ,6 ,7 ,8 ,9 ,13 ,15 )
disp ( From t h e map , low o u t p u t s f o r
2 ,4 ,5 ,10 ,11 ,12 ,14 )
// g i v e n l o g i c e q u a t i o n //
a =[0 0 0 0;0 0 0 1;0 0 1 1 ;0 1 1 0;0 1 1 1;1 0 0 0
;1 0 0 1;1 1 0 1;1 1 1 1]
disp ( a )
c =[0 0 1 0;0 1 0 0;0 1 0 1;1 0 1 0;1 0 1 1;1 1 0 0;1
1 1 0]
disp ( c )
for i =1: 9
if a (i ,1) ==1 then
b (i ,1) = A
else
b (i ,1) = A
end
if a (i ,2) ==1 then
b (i ,2) = B
else
b (i ,2) = B
end
if a (i ,3) ==1 then
b (i ,3) = C
else
b (i ,3) = C
end
if a (i ,4) ==1 then
b (i ,4) = D
else
b (i ,4) = D
end
end
for i =1: 7
if c (i ,1) ==1 then
d (i ,1) = A
84
46
else
47
d (i ,1) = A
48
end
49
if c (i ,2) ==1 then
50
d (i ,2) = B
51
else
52
d (i ,2) = B
53
end
54
if c (i ,3) ==1 then
55
d (i ,3) = C
56
else
57
d (i ,3) = C
58
end
59
if c (i ,4) ==1 then
60
d (i ,4) = D
61
else
62
d (i ,4) = D
63
end
64 end
65 disp ( e v a l u a t i n g e x p r e s s i o n ( m i n t e r m s ) from t r u t h
66
67
68
69
70
71
72
73
74
75
76
77
78
t a b l e and map )
x1 = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ,b (1 ,4) ])
x2 = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ,b (2 ,4) ])
x3 = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ,b (3 ,4) ])
x4 = strcat ([ b (4 ,1) ,b (4 ,2) ,b (4 ,3) ,b (4 ,4) ])
x5 = strcat ([ b (5 ,1) ,b (5 ,2) ,b (5 ,3) ,b (5 ,4) ])
x6 = strcat ([ b (6 ,1) ,b (6 ,2) ,b (6 ,3) ,b (6 ,4) ])
x7 = strcat ([ b (7 ,1) ,b (7 ,2) ,b (7 ,3) ,b (7 ,4) ])
x8 = strcat ([ b (8 ,1) ,b (8 ,2) ,b (8 ,3) ,b (8 ,4) ])
x9 = strcat ([ b (9 ,1) ,b (9 ,2) ,b (9 ,3) ,b (9 ,4) ])
x =([ x1 + , x2 + , x3 + , x4 + , x5 + , x6 + , x7 + , x8 + ,
x9 ])
disp ( x )
disp ( e v a l u a t i n g e x p r e s s i o n ( maxterms ) from t r u t h
t a b l e and map )
disp ( (A+B+C +D) . ( A+B +C+D) . ( A+B +C+D ) . ( A +B+
C +D) . ( A +B+C +D ) . ( A +B +C+D) . ( A +B +C
+D) )
85
// E x p r e s s i o n i s d i s p l a y e d //
disp ( now r e d u c i n g e x p r e s s i o n u s i n g b o o l e a n a l g e b r a
)
81 disp ( SOP B C +A B D+A BC+ABD
i e 15
inputs )
82 disp ( POS (B+C +D) (A +B +D) (A+B +C) (A +B+C )
i e 16 i n p u t s )
83 disp ( T h e r e f o r e SOP form i s l e s s e x p e n s i v e )
79
80
9
10
11
12
13
14
15
(2 ,3 ,4 ,5 ,6 ,7 ,12 ,13 ,14 ,15 ,18 ,19 ,20 ,21 ,22 ,23 ,28 ,29 ,30 ,31)
)
disp (
A
A
)
disp (
D E D E DE DE
D E D
E DE DE )
disp ( B C
0
0
1 1
0
0
1 1
)
disp ( BC
1
1
1 1
1
1
1 1
)
disp ( BC
1
1
1 1
1
1
1 1
)
disp ( BC
0
0
0 0
0
0
0 0
)
disp ( From t h e map , h i g h o u t p u t s f o r
2 ,3 ,4 ,5 ,6 ,7 ,12 ,13 ,14 ,15 ,18 ,19 ,20 ,21 ,22 ,23 ,28 ,29 ,30 ,31
86
16
17
18
19
)
// T h e r e f o r e t h e kmap i s d i s p l a y e d //
disp ( T h e r e f o r e t h e minimum e x p r e s s i o n i s : )
disp ( Y=C+B D )
// r e s u l t i s d i s p l a y e d //
26
else
27
d (i ,2) = B
28
end
29
if c (i ,3) ==1 then
30
d (i ,3) = C
31
else
32
d (i ,3) = C
33
end
34
if c (i ,4) ==1 then
35
d (i ,4) = D
36
else
37
d (i ,4) = D
38
end
39 end
40 disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h
41
42
43
44
45
46
47
48
49
50
51
52
53
54
map )
l = strcat ([ d (1 ,1) ,d (1 ,2) ,d (1 ,3) ,d (1 ,4) ])
m = strcat ([ d (2 ,1) ,d (2 ,2) ,d (2 ,3) ,d (2 ,4) ])
n = strcat ([ d (3 ,1) ,d (3 ,2) ,d (3 ,3) ,d (3 ,4) ])
o = strcat ([ d (4 ,1) ,d (4 ,2) ,d (4 ,3) ,d (4 ,4) ])
x = strcat ([ l + ,m + ,n + ,o ])
disp ( t h e sum o f p r o d u c t e x p r e s s i o n i s : )
disp ( x )
disp ( R e a d i n g t h e SOP form )
disp ( A B CD +BC D +AB D+AC )
// E x p r e s s i o n i s d i s p l a y e d //
disp ( now r e d u c i n g e x p r e s s i o n u s i n g b o o l e a n a l g e b r a
from POS )
disp ( (A+B+C) (A +C +D) (A+D ) (B +C ) )
disp ( POS h a s 14 i n p u t s , SOP h a s 16 i n p u t s )
disp ( T h e r e f o r e , POS form i s l e s s e x p e n s i v e )
t a b l e and
// Example 6 20//
88
2 // Find minimum o f e x p r e s s i o n //
3 clc
4 // c l e a r s t h e c o n s o l e //
5 clear
6 // c l e a r s a l l e x i s t i n g v a r i a b l e s //
7 // Mapping t h e e x p r e s s i o n //
8 disp ( Y=M( 0 , 1 , 9 , 1 0 , 1 1 , 1 3 , 1 4 , 1 5 , 1 6 , 1 7 , 2 2 , 2 3 , 2 6 , 2 7 ) )
9 disp (
A
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
A
)
disp (
D E D E DE DE
D E D
E DE DE )
disp ( B C
0
0
1 1
0
0
1 1
)
disp ( BC
1
1
1 1
1
1
0 0
)
disp ( BC
1
0
0 0
1
1
1 1
)
disp ( BC
1
0
0 0
1
1
0 0
)
disp ( From t h e map , h i g h o u t p u t s f o r
0 ,1 ,9 ,10 ,11 ,13 ,14 ,15 ,16 ,17 ,22 ,23 ,26 ,27 )
// T h e r e f o r e t h e kmap i s d i s p l a y e d //
disp ( The SOP o f e x p r e s s i o n i s : )
disp ( Y=B C D+A B C+ABC+BD E +ACD +ABD )
disp ( 24 i n p u t s )
disp ( The POS o f e x p r e s s i o n i s : )
disp ( Y=(B+C+D) (B +C+D ) (A +B+C+D) (A+B +E ) (A+B
+D ) )
disp ( 21 i n p u t s )
disp ( T h e r e f o r e POS form i s t h e minimum e x p r e s s i o n )
// r e s u l t i s d i s p l a y e d //
// Example 6 24//
89
2 // S o l v e m u l t i p l e o u t p u t e q u a t i o n u s i n g mapping //
3 clc
4 // c l e a r s t h e window //
5 clear
6 // c l e a r s a l l e x i s t i n g v a r i a b l e s //
7 disp ( f 1=Sigma m( 0 , 1 , 2 , 4 , 6 , 7 , 1 0 , 1 4 , 1 5 ) )
8 // F i r s t f u n c t i o n i s d i s p l a y e d //
9 disp ( f 2=Sigma m( 3 , 4 , 5 , 9 , 1 0 , 1 1 , 1 4 ) )
10 // S e c o n d f u n c t i o n i s d i s p l a y e d //
11 disp ( f 1 . f 2=Sigma m( 4 , 1 0 , 1 4 ) )
12 // Taking t h e common e n t r i e s //
13 disp ( Mapping f o r f 1 . f 2 )
14 disp (
C D C D CD CD )
15 disp ( A B
0
0
0 0 )
16 disp ( AB
1
0
0 0 )
17 disp ( AB
0
0
0 1 )
18 disp ( AB
0
0
0 1 )
19 disp ( From t h e map , h i g h o u t p u t s f o r 4 , 1 0 , 1 4 )
20 // g i v e n l o g i c e q u a t i o n //
21 a =[0 1 0 0;1 0 1 0;1 1 1 0]
22 disp ( a )
23 for i =1: 3
24
if a (i ,1) ==1 then
25
b (i ,1) = A
26
else
27
b (i ,1) = A
28
end
29
if a (i ,2) ==1 then
30
b (i ,2) = B
31
else
32
b (i ,2) = B
33
end
34
if a (i ,3) ==1 then
35
b (i ,3) = C
36
else
37
b (i ,3) = C
38
end
39
if a (i ,4) ==1 then
90
40
b (i ,4) = D
41
else
42
b (i ,4) = D
43
end
44 end
45 disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h
t a b l e and
map )
l = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ,b (1 ,4) ])
m = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ,b (2 ,4) ])
n = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ,b (3 ,4) ])
x = strcat ([ l + ,m + ,n ])
disp ( x )
// E x p r e s s i o n i s d i s p l a y e d //
disp ( now r e d u c i n g e x p r e s s i o n u s i n g b o o l e a n a l g e b r a
)
53 disp ( ACD +A BC D )
46
47
48
49
50
51
52
91
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
disp ( AB
0
0
X 1 )
disp ( AB
0
0
0 0 )
disp ( From t h e map , h i g h o u t p u t s f o r 1 , 7 , 1 4 and
dont c a r e s f o r 5 ,15 )
// g i v e n l o g i c e q u a t i o n //
a =[0 0 0 1;0 1 0 1;0 1 1 1;1 1 1 0;1 1 1 1]
disp ( a )
for i =1: 5
if a (i ,1) ==1 then
b (i ,1) = A
else
b (i ,1) = A
end
if a (i ,2) ==1 then
b (i ,2) = B
else
b (i ,2) = B
end
if a (i ,3) ==1 then
b (i ,3) = C
else
b (i ,3) = C
end
if a (i ,4) ==1 then
b (i ,4) = D
else
b (i ,4) = D
end
end
disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h t a b l e and
map )
l = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ,b (1 ,4) ])
m = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ,b (2 ,4) ])
n = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ,b (3 ,4) ])
o = strcat ([ b (4 ,1) ,b (4 ,2) ,b (4 ,3) ,b (4 ,4) ])
p = strcat ([ b (5 ,1) ,b (5 ,2) ,b (5 ,3) ,b (5 ,4) ])
x = strcat ([ l + ,m + ,n + ,o + ,p ])
disp ( x )
92
// E x p r e s s i o n i s d i s p l a y e d //
disp ( now r e d u c i n g e x p r e s s i o n u s i n g b o o l e a n a l g e b r a
)
55 disp ( ABC+A C D+A BD )
53
54
BC D +ABC D+ABC D )
disp ( C o n v e r t i n g t h e 4 v a r i a b l e m i n t e r m s t o 3
v a r i a b l e minterms )
disp ( M=m1D +m1D+m5D +m5D+m3D+m3D +m6D+m6D +m2D
)
disp ( u s i n g D+D =1 )
disp ( R e s u l t M= B C+A CD+BC D +ABC )
// f i n a l e x p r e s s i o n i s d i s p l a y e d //
D +ABCD )
93
disp ( C o n v e r t i n g t h e 6 v a r i a b l e m i n t e r m s t o 4
v a r i a b l e minterms )
9 disp ( m7E+E ; m14F+F )
10 disp ( R e s u l t Z= A CDE+A BDE +ABD +ACD F )
11 // f i n a l e x p r e s s i o n i s d i s p l a y e d //
8
F m8+F m9) )
8 disp ( C o n v e r t i n g t h e 7 v a r i a b l e m i n t e r m s t o 4
v a r i a b l e minterms )
94
9
10
11
0 ,2 ,3 ,6 ,7 ,8 ,9 ,10 ,13 )
// g i v e n l o g i c e q u a t i o n //
a =[0 0 0 0;0 0 1 0;0 0 1 1 ;0 1 1 0;0 1 1 1;1 0 0 0
;1 0 0 1;1 0 1 0;1 1 0 1]
disp ( a )
for i =1: 9
if a (i ,1) ==1 then
b (i ,1) = A
else
b (i ,1) = A
end
if a (i ,2) ==1 then
b (i ,2) = B
else
95
26
b (i ,2) = B
27
end
28
if a (i ,3) ==1 then
29
b (i ,3) = C
30
else
31
b (i ,3) = C
32
end
33
if a (i ,4) ==1 then
34
b (i ,4) = D
35
else
36
b (i ,4) = D
37
end
38 end
39 disp ( e v a l u a t i n g e x p r e s s i o n from t r u t h
40
41
42
43
44
45
46
47
48
49
50
51
52
53
t a b l e and
map )
x1 = strcat ([ b (1 ,1) ,b (1 ,2) ,b (1 ,3) ,b (1 ,4) ])
x2 = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ,b (2 ,4) ])
x3 = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ,b (3 ,4) ])
x4 = strcat ([ b (4 ,1) ,b (4 ,2) ,b (4 ,3) ,b (4 ,4) ])
x5 = strcat ([ b (5 ,1) ,b (5 ,2) ,b (5 ,3) ,b (5 ,4) ])
x6 = strcat ([ b (6 ,1) ,b (6 ,2) ,b (6 ,3) ,b (6 ,4) ])
x7 = strcat ([ b (7 ,1) ,b (7 ,2) ,b (7 ,3) ,b (7 ,4) ])
x8 = strcat ([ b (8 ,1) ,b (8 ,2) ,b (8 ,3) ,b (8 ,4) ])
x9 = strcat ([ b (9 ,1) ,b (9 ,2) ,b (9 ,3) ,b (9 ,4) ])
x =([ x1 + , x2 + , x3 + , x4 + , x5 + , x6 + , x7 + , x8 + ,
x9 ])
disp ( x )
// E x p r e s s i o n i s d i s p l a y e d //
disp ( now r e d u c i n g e x p r e s s i o n u s i n g b o o l e a n a l g e b r a
)
disp ( B D +A C+AC D )
96
Chapter 11
Analog Digital Conversion
10
11
12
13
14
b i t s i s t h e b i n a r y number 1 1 1 1 1 i e 31 i n d e c i m a l
form )
pres =(1/((2^ n ) -1) ) *100
// p r e s d e n o t e s t h e p e r c e n t r e s o l u t i o n //
disp ( T h e r e f o r e t h e p e r c e n t r e s o l u t i o n o f t h e 5 b i t
D/A c o n v e r t e r i s : )
disp ( pres )
// a n s w e r i s d i s p l a y e d //
1 // Example 11 2//
2 clc
3 // c l e a r s t h e c o n s o l e //
4 clear
5 // c l e a r s a l l e x i s t i n g v a r i a b l e s //
6 n =6
7 mpsv =20
8 // n d e n o t e s t h e number o f b i t s , mpsv d e n o t e s t h e max .
9
10
11
12
13
14
15
16
17
18
19
p r e c i s i o n s u p p l y v o l t a g e //
disp ( Each b i t r e p r e s e n t s 1 / ( 2 6 ) 1 o f t h e t o t a l 20V
)
E1 =(1/63) *20
// g i v e n a b i n a r y number 1 0 0 1 1 0 whose v o l t a g e v a l u e
i s t o be f o u n d //
a =100110
b = bin2dec ( 1 0 0 1 1 0 )
E2 =( b /((2^6) -1) ) *20
disp ( The v o l t a g e c h a n g e t h a t e a c h LSB r e p r e s e n t s i s
: )
disp ( E1 )
disp ( The v o l t a g e t h a t t h e b i n a r y number 1 0 0 1 1 0
represents is : )
disp ( E2 )
// a n s w e r s a r e d i s p l a y e d //
98
9 Ein =3.2
10 // Given t h e
11
12
13
14
15
16
17
18
19
r e s i s t a n c e v a l u e s i n k i l o ohms and t h e
i n p u t v o l t a g e i n v o l t s //
Av = Rf / Rs
//Av d e n o t e s t h e g a i n o f t h e opamp//
Eo = Av * Ein
// Eo d e n o t e s t h e o u t p u t v o l t a g e //
disp ( The v o l t a g e g a i n o f t h e g i v e n opamp i s : )
disp ( Av )
disp ( The o u t p u t v o l t a g e o f t h e opamp i n v o l t s i s :
)
disp ( Eo )
// r e s u l t s a r e d i s p l a y e d //
99
18
19
20
21
22
23
24
25
26
27
28
disp ( t h e c u r r e n t t h r o u g h t r e s i s t o r R2 i n m i l l i amps
is : )
I2 = E2 / R2
disp ( I2 )
disp ( t h e c u r r e n t t h r o u g h t r e s i s t o r R3 i n m i l l i amps
is : )
I3 = E3 / R3
disp ( I3 )
Eo = -( I1 + I2 + I3 ) * Rf
// Eo d e n o t e s t h e o u t p u t v o l t a g e //
disp ( The o u t p u t v o l t a g e i n v o l t s o f t h e c i r c u i t i s :
)
disp ( Eo )
// a n s w e r i s d i s p l a y e d //
// Example 11 5//
// compute o u t p u t v o l t a g e f o r t h e c i r c u i t i n f i g .
11 13//
clc
// c l e a r s t h e c o n s o l e //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
disp ( s w i t c h c o n f i g u r a t i o n ABCD i s 0 1 1 0 )
E =8
RA =1
RB =2
RC =4
RD =8
Rf =1
// Given a l l t h e r e s i s t a n c e v a l u e s i n k i l o ohms and
t h e common v o l t a g e E i n v o l t s //
disp ( t h e c u r r e n t t h r o u g h t r e s i s t o r RA i n m i l l i amps
is : )
100
16 IA =0
17 // s w i t c h A i s open //
18 disp ( IA )
19 disp ( t h e c u r r e n t t h r o u g h t
i n m i l l i amps
20
21
22
i n m i l l i amps
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
r e s i s t o r RB
is : )
IB = E / RB
disp ( IB )
disp ( t h e c u r r e n t t h r o u g h t r e s i s t o r RC
is : )
IC = E / RC
disp ( IC )
disp ( t h e c u r r e n t t h r o u g h t r e s i s t o r RD
is : )
ID =0
// s w i t c h D i s open //
disp ( ID )
Itot = IA + IB + IC + ID
// t o t a l c u r r e n t i s d e n o t e d by I t o t //
If = Itot
Eo = If * Rf
Eo = Eo *( -1)
// Eo d e n o t e s o u t p u t v o l t a g e //
disp ( Output v o l t a g e o f t h e c i r c u i t i n
disp ( Eo )
// r e s u l t i s d i s p l a y e d //
i n m i l l i amps
volts is :
Scilab code Exa 11.6 Resolution and Percent resolution 12bit DAconverter
// Example 11 6//
// r e s o l u t i o n and p e r c e n t r e s o l u t i o n o f a 12 b i t D/A
c o n v e r t e r , o u t p u t v a r i e s from 50 t o 5 0 / /
3 clc
4 // c l e a r s t h e window //
5 clear
1
2
101
6 // c l e a r s a l l e x i s t i n g v a r i a b l e s //
7 E =50 -( -50)
8 n =12
9 // g i v e n t h e v o l t a g e r a n g e E i n v o l t s and t h e number
10
11
12
13
14
15
16
17
o f b i t s n //
disp ( 12 b i t c o n v e r t e r can have ( 2 1 2 ) 1 non z e r o
states )
Res = E /((2^ n ) -1)
Pres =1/((2^ n ) -1) *(100)
disp ( t h e r e s o l u t i o n i n v o l t s i s : )
disp ( Res )
disp ( t h e p e r c e n t r e s o l u t i o n i s : )
disp ( Pres )
// a n s w e r s a r e d i s p l a y e d //
Scilab code Exa 11.7 Resolution and Percent resolution 10bit ADconverter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Example 11 7//
// r e s o l u t i o n and p e r c e n t r e s o l u t i o n o f a 10 b i t D/A
c o n v e r t e r , i n p u t v o l t a g e v a r i e s from 10 t o 1 0 / /
clc
// c l e a r s t h e window //
clear
// c l e a r s a l l e x i s t i n g v a r i a b l e s //
E =10 -( -10)
n =10
// g i v e n t h e v o l t a g e r a n g e E i n v o l t s and t h e number
o f b i t s n //
disp ( 10 b i t c o n v e r t e r can have ( 2 1 0 ) 1 non z e r o
states )
Res = E /((2^ n ) -1)
Pres =1/((2^ n ) -1) *(100)
disp ( t h e r e s o l u t i o n i n m i l l i v o l t s i s : )
disp ( Res *1000)
102
15
16
17
disp ( t h e p e r c e n t r e s o l u t i o n i s :
disp ( Pres )
// a n s w e r s a r e d i s p l a y e d //
103