Download as pdf or txt
Download as pdf or txt
You are on page 1of 92

Scilab Textbook Companion for

Modern Digital Electronics


by R. P. Jain1
Created by
Shikha Garg
DIGITAL ELECTRONICS
Instrumentation Engineering
THAPAR UNIVERSITY
College Teacher
Mr. Sunil Kumar Singla
Cross-Checked by

August 17, 2013

1 Funded

by a grant from the National Mission on Education through ICT,


http://spoken-tutorial.org/NMEICT-Intro. This Textbook Companion and Scilab
codes written in it can be downloaded from the Textbook Companion Project
section at the website http://scilab.in

Book Description
Title: Modern Digital Electronics
Author: R. P. Jain
Publisher: Tata McGraw - Hill Education, New Delhi
Edition: 4
Year: 2010
ISBN: 9780070669116

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

1 Fundamental Concepts

2 Number System and Codes

13

3 Semiconductor devices switching mode operation

47

4 Digital Logic Families

52

5 Combinational Logic Design

55

6 Combinational Logic Design using MSI circuits

58

7 Flip flops

75

8 Sequential Logic Design

77

9 Timing Circuits

78

10 A to D and D to A Converters

79

11 Semiconductor Memories

84

12 Programmable Logic Design

89

14 Computer Aided Design of Digital Systems

90

List of Scilab Codes


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

1.1
1.3
1.7.a
1.7.b
1.9.a
1.9.b
1.11.a
1.11.b
1.13.a
1.13.b
2.1
2.2.a
2.2.b
2.2.c
2.2.d
2.3.a
2.3.b
2.3.c
2.3.d
2.4
2.5
2.6.a
2.6.b
2.6.c
2.8.a
2.8.b
2.9.a
2.9.b

And Gate . . . . . . . . . . . . . . . . . . . . . . . .
or gate . . . . . . . . . . . . . . . . . . . . . . . . .
NAND gate . . . . . . . . . . . . . . . . . . . . . . .
NAND gate with one permanently connected to logic
NOR gate connected to 0 logic as one input . . . . .
NOR gate with one input connected to logic 1 . . . .
EXOR gate with one input permanently as logic 0 .
EXOR gate with one input permanently as logic 1 .
EXNOR gate with one input permanently as logic 0
EXNOR gate with one input permanently as logic 1
decimal equivalent . . . . . . . . . . . . . . . . . . .
conversion . . . . . . . . . . . . . . . . . . . . . . . .
conversion . . . . . . . . . . . . . . . . . . . . . . . .
conversion . . . . . . . . . . . . . . . . . . . . . . . .
conversion . . . . . . . . . . . . . . . . . . . . . . . .
decimal representation . . . . . . . . . . . . . . . . .
decimal representation . . . . . . . . . . . . . . . . .
decimal conversion . . . . . . . . . . . . . . . . . . .
decimal representation . . . . . . . . . . . . . . . . .
binary conversion . . . . . . . . . . . . . . . . . . . .
conversion . . . . . . . . . . . . . . . . . . . . . . . .
dec to bin . . . . . . . . . . . . . . . . . . . . . . . .
dec to bin . . . . . . . . . . . . . . . . . . . . . . . .
dec to bin . . . . . . . . . . . . . . . . . . . . . . . .
ones complement . . . . . . . . . . . . . . . . . . . .
ones complement of unsigned no . . . . . . . . . . .
ones comp . . . . . . . . . . . . . . . . . . . . . . .
ones complement of signed no . . . . . . . . . . . . .
4

.
.
.
1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

7
7
8
9
9
9
10
10
11
11
13
13
14
14
14
15
16
18
20
22
22
23
25
26
27
28
28
29

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.9.c
2.10.a
2.10.b
2.11.a
2.11.b
2.11.c
2.11.d
2.13.a
2.13.b
2.14
2.15
2.16
2.17
2.21
2.22
2.23
2.26
2.27.a
2.27.b
2.30
2.31
2.33
2.35
2.36.a
2.36.b
3.3
3.4.a
3.4.b
3.5.a
3.5.b
3.7.a
3.7.b

ones complement of signed no . . . . . . . . . . . . . .


twos complement . . . . . . . . . . . . . . . . . . . . .
twos complement of binary no . . . . . . . . . . . . . .
complement . . . . . . . . . . . . . . . . . . . . . . . .
complement . . . . . . . . . . . . . . . . . . . . . . . .
complement . . . . . . . . . . . . . . . . . . . . . . . .
twos complement of binary number . . . . . . . . . . .
addition . . . . . . . . . . . . . . . . . . . . . . . . . .
addition of binary numbers . . . . . . . . . . . . . . .
addition of 4 binary numbers . . . . . . . . . . . . . .
subtraction of binary numbers . . . . . . . . . . . . .
multiplication of binary numbers . . . . . . . . . . . .
division of binary numbers . . . . . . . . . . . . . . .
decimal to octal conversion . . . . . . . . . . . . . . .
convert octal to binary . . . . . . . . . . . . . . . . . .
binary to octal . . . . . . . . . . . . . . . . . . . . . .
addition of octal numbers . . . . . . . . . . . . . . . .
addition of octal numbers . . . . . . . . . . . . . . . .
addition of OCTAL numbers . . . . . . . . . . . . . .
convert hexadecimal to binary . . . . . . . . . . . . .
binary to hexadecimal number . . . . . . . . . . . . .
hexadecimal to octal number . . . . . . . . . . . . . .
addition of hexadecimal numbers . . . . . . . . . . . .
subtraction of hexadecimal numbers . . . . . . . . . .
subtraction of hexadecimal numbers . . . . . . . . . .
response of transistor inverter . . . . . . . . . . . . . .
output voltage of JFET . . . . . . . . . . . . . . . . .
output voltage of JFET . . . . . . . . . . . . . . . . .
output characateristics of a MOSFET . . . . . . . . .
output voltage for MOSFET . . . . . . . . . . . . . .
output voltage for identical set of transistors . . . . .
output voltage in identical transistors for input voltage
5V . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.1.a.i calculate fan out when all inputs are high . . . . . . .
4.1.a.iicalculate fan out for DTL NAND gate when atleast one
input is LOW . . . . . . . . . . . . . . . . . . . . . . .
5.1
simplification of equation . . . . . . . . . . . . . . . .
5.2
conversion to canonical SOP form . . . . . . . . . . .
5

30
31
31
32
33
33
34
35
35
36
37
37
38
39
39
40
40
41
42
43
43
44
44
45
46
47
48
49
49
50
50
51
52
53
55
56

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

5.3
conversion to canonical POS form . . . . . . . . . . .
6.1
boolean equation using 8 to 1 mux . . . . . . . . . . .
6.4.a subtraction . . . . . . . . . . . . . . . . . . . . . . . .
6.4.b subtraction . . . . . . . . . . . . . . . . . . . . . . . .
6.5.a.i 8 bit adder . . . . . . . . . . . . . . . . . . . . . . . .
6.5.a.ii8 bit subtractor . . . . . . . . . . . . . . . . . . . . . .
6.5.b.i 8 bit adder . . . . . . . . . . . . . . . . . . . . . . . .
6.5.b.ii8 bit subtractor . . . . . . . . . . . . . . . . . . . . . .
7.1
clocked SR flip flop . . . . . . . . . . . . . . . . . . . .
7.2
convert SR flip flop to JK flip flop . . . . . . . . . . .
8.2
maximum frequency . . . . . . . . . . . . . . . . . . .
9.3
Schmitt trigger . . . . . . . . . . . . . . . . . . . . . .
10.1 find analog output of 4 bit D to A converter . . . . . .
10.2.a 4 bit unipolar D to A converter . . . . . . . . . . . . .
10.2.b 4 bit unipolar D to A converter after adjusting the offset
voltage . . . . . . . . . . . . . . . . . . . . . . . . . .
10.2.c 4 bit unipolar D to A converter after complimenting MSB
10.3 D to A converter in ones complement form . . . . . .
10.4 2 decade BCD D to A converter . . . . . . . . . . . .
10.5 determine the quantization interval . . . . . . . . . . .
11.1 Binary address of each location of size 16 words . . . .
11.2.a maximum rate at which data can be stored . . . . . .
11.2.b maximum rate at which data can be read . . . . . . .
11.6.a data output . . . . . . . . . . . . . . . . . . . . . . . .
11.6.b data output . . . . . . . . . . . . . . . . . . . . . . . .
11.6.c data output . . . . . . . . . . . . . . . . . . . . . . . .
11.6.d data output . . . . . . . . . . . . . . . . . . . . . . . .
11.7.a output and change in memory location . . . . . . . . .
12.1 find the product term . . . . . . . . . . . . . . . . . .
14.2 entity construction for EXOR circuit . . . . . . . . . .

56
58
60
63
65
67
70
72
75
76
77
78
79
80
80
81
82
82
83
84
85
85
86
86
87
87
88
89
90

Chapter 1
Fundamental Concepts

Scilab code Exa 1.1 And Gate


1 // e x a m p l e 1 . 1 / /
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s t h e e x i s t i n g v a r i a b l e s //
6 disp ( t h e l o c k e r d o o r (Y) can be o p e n e d u s i n g one

key (A) which i s w i t h you and t h e o t h e r key (B)


which i s w i t h t h e bank e x e c u t i v e . When b o t h t h e
k e y s a r e used , t h e l o c k e r d o o r opens , i . e . t h e
l o c k e r d o o r can be o p e n e d (Y=1) o n l y when b o t h
t h e k e y s a r e a p p l i e d (A=B=1) . Thus , t h i s can be
e x p r e s s e d a s an AND o p e r a t i o n )
7 disp ( Y=AB )

Scilab code Exa 1.3 or gate


7

1 // e x a m p l e 1 . 3 / /
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( L e t t h e t e m p e r a t u r e and p r e s s u r e be c o n v e r t e d

i n t o e l e c t r i c a l s i g n a l s and T=1 i f t e m p e r a t u r e
e x c e e d s t h e s p e c i f i e d l i m i t and P=1 i f p r e s s u r e
e x c e e d s t h e s p e c i f i e d l i m i t . I f T=1 o r P=1 o r
b o t h T and P a r e 1 t h e n t h e a l a r m i s r e q u i r e d t o
be a c t i v a t e d , i . e . , t h e s i g n a l a p p l i e d t o t h e
a l a r m Y=1. T h i s o p e r a t i o n can be e x p r e s s e d a s an
or operation . )
7 disp ( Y=T o r P )
8 disp ( Y=T+P )

Scilab code Exa 1.7.a NAND gate


1 // e x a m p l e 1 . 7 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( when one o f t h e l o g i c i n p u t o f 2 i n p u t NAND

gate i s 0 , then i r r e s p e c t i v e o f the other input ,


t h e o u t p u t comes o u t t o be 1 . I n f a c t , a NAND
g a t e i s d i s a b l e d o r i n h i b i t e d i f one o f i t s
inputs i s connected to l o g i c 0 )
7 disp ( Y=1 )

Scilab code Exa 1.7.b NAND gate with one permanently connected to
logic 1
1 // e x a m p l e 1 . 7 ( b ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( when one o f t h e l o g i c i n p u t o f 2 i n p u t NAND

g a t e i s 1 , t h e n when A=1 , Y=0 and i f A=0 , Y=1 )


7 disp ( Y=A )

Scilab code Exa 1.9.a NOR gate connected to 0 logic as one input
1 // e x a m p l e 1 . 9 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( when one o f t h e l o g i c i n p u t o f 2 i n p u t NOR
7

g a t e i s 0 , t h e n when A=1 , Y=0 and i f A=0 , Y=1 )


disp ( Y=A )

Scilab code Exa 1.9.b NOR gate with one input connected to logic 1
9

1 // e x a m p l e 1 . 9 ( b ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( when one o f t h e l o g i c i n p u t o f 2 i n p u t NOR

gate i s 1 , then i r r e s p e c t i v e o f the other input ,


t h e o u t p u t comes o u t t o be 0 . I n f a c t , a NAND
g a t e i s d i s a b l e d o r i n h i b i t e d i f one o f i t s
inputs i s connected to l o g i c 1 )
7 disp ( Y=0 )
8 disp ( h e r e t h e o u t p u t o f Y i s 0 i r r e s p e c t i v e o f
input of A)

Scilab code Exa 1.11.a EXOR gate with one input permanently as logic
0
1 // e x a m p l e 1 . 1 1 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( I f we c o n n e c t one i n p u t o f EXOR g a t e t o 0
7

p e r m a n e n t l y , we o b s e r v e t h a t Y=A0 +A 0 )
disp ( t h u s , Y=A )

Scilab code Exa 1.11.b EXOR gate with one input permanently as logic
1

10

1 // e x a m p l e 1 . 1 1 ( b ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( I f we c o n n e c t one i n p u t o f EXOR g a t e t o 1
7

p e r m a n e n t l y , we o b s e r v e t h a t Y=A1 +A 1 )
disp ( t h u s , Y=A )

Scilab code Exa 1.13.a EXNOR gate with one input permanently as logic
0
1 // e x a m p l e 1 . 1 3 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( I f we c o n n e c t one i n p u t o f EXNOR g a t e t o 0

p e r m a n e n t l y , we o b s e r v e t h a t Y=A0+A 0 )
7 disp ( t h u s , Y=A )

Scilab code Exa 1.13.b EXNOR gate with one input permanently as logic
1
1 // e x a m p l e 1 . 1 3 ( b ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g

v a r i a b l e s //
11

disp ( I f we c o n n e c t one i n p u t o f EXNOR g a t e t o 1


p e r m a n e n t l y , we o b s e r v e t h a t Y=A1+A 1 )
7 disp ( t h u s , Y=A )
6

12

Chapter 2
Number System and Codes

Scilab code Exa 2.1 decimal equivalent


1 // e x a m p l e 2 . 1 / /
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 ans = bin2dec ( 1 1 1 1 1 )
4 // d e c i m a l e q u i v a l e n t o f b i n a r y number //
5 disp ( ans )
6 // a n s w e r i n d e c i m a l form //

Scilab code Exa 2.2.a conversion


1 // e x a m p l e 2 . 2 ( a ) //
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 ans = bin2dec ( 1 1 0 1 0 1 )
4 // d e c i m a l e q u i v a l e n t o f b i n a r y number //
5 disp ( ans )
6 // a n s w e r i n d e c i m a l form //

13

Scilab code Exa 2.2.b conversion


1 // e x a m p l e 2 . 2 ( b ) //
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 ans = bin2dec ( 1 0 1 1 0 1 )
4 // d e c i m a l e q u i v a l e n t o f b i n a r y number //
5 disp ( ans )
6 // a n s w e r i n d e c i m a l form //

Scilab code Exa 2.2.c conversion


1 // e x a m p l e 2 . 2 ( c ) //
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 ans = bin2dec ( 1 1 1 1 1 1 1 1 )
4 // d e c i m a l e q u i v a l e n t o f b i n a r y number //
5 disp ( ans )
6 // a n s w e r i n d e c i m a l form //

Scilab code Exa 2.2.d conversion


1

// e x a m p l e 2 . 2 ( d ) //
14

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 ans = bin2dec ( 0 0 0 0 0 0 0 0 )
4 // d e c i m a l e q u i v a l e n t o f b i n a r y number //
5 disp ( ans )
6 // a n s w e r i n d e c i m a l form //

Scilab code Exa 2.3.a decimal representation


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// e x a m p l e 2 . 3 ( a ) //
clc
// c l e a r s t h e command window //
clear
// c l e a r s //
p =1;
// i n i t i a l i s i n g //
q =1;
z =0;
b =0;
w =0;
f =0;
// b i n= i n p u t (
E n t e r t h e b i n a r y no t o be
converted to i t s decimal e q u i v a l e n t :
)
// a c c e p t i n g t h e b i n a r y i n p u t from u s e r //
bin =101101.10101;
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 and 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)
// Loop t o t a k e t h e b i n a r y b i t s o f i n t e g e r i n t o a
m a t r i x //
r = modulo ( a ,10) ;
b (1 , q ) = r ;
a = a /10;
15

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

a = floor ( a ) ;
q = q +1;
end
for m =1: q -1
// m u l t i p l i y i n g t h e b i t s o f i n t e g e r w i t h t h e i r
p o s i t i o n v a l u e s and a d d i n g //
c = m -1;
f = f + b (1 , m ) *(2^ c ) ;
end
while ( d >0)
// Loop t o t a k e t h e b i n a r y b i t s o f d e c i m a l 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
// m u l t i p l i y i n g t h e b i t s o f d e c i m a l w i t h t h e i r
p o s i t i o n v a l u e s and a d d i n g //
z = z + w (1 , n ) *(0.5) ^(11 - n ) ;
end
z = z *10000;
// r o u n d i n g o f t o 4 d e c i m a l v a l u e s //
z = round ( z ) ;
z = z /10000;
x=f+z;
disp ( The 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
g i v e n i s );
disp ( x ) ;
// D i s p l a y i n g t h e f i n a l r e s u l t //

16

Scilab code Exa 2.3.b decimal representation


1
2
3
4
5
6
7
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

// e x a m p l e 2 . 3 ( b ) //
clc
// c l e a r s t h e command window //
clear
// c l e a r s //
p =1;
// i n i t i a l i s i n g //
q =1;
z =0;
b =0;
w =0;
f =0;
// b i n= i n p u t (
E n t e r t h e b i n a r y no t o be
converted to i t s decimal e q u i v a l e n t :
)
// a c c e p t i n g t h e b i n a r y i n p u t from u s e r //
bin =1100.1011;
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 and 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)
// Loop t o t a k e t h e b i n a r y b i t s o f i n t e g e r 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 i y i n g t h e b i t s o f i n t e g e r w i t h t h e i r
p o s i t i o n v a l u e s and a d d i n g //
c = m -1;
f = f + b (1 , m ) *(2^ c ) ;
end
17

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

while ( d >0)
// Loop t o t a k e t h e b i n a r y b i t s o f d e c i m a l 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
// m u l t i p l i y i n g t h e b i t s o f d e c i m a l w i t h t h e i r
p o s i t i o n v a l u e s and a d d i n g //
z = z + w (1 , n ) *(0.5) ^(11 - n ) ;
end
z = z *10000;
// r o u n d i n g o f t o 4 d e c i m a l v a l u e s //
z = round ( z ) ;
z = z /10000;
x=f+z;
disp ( The 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
g i v e n i s );
disp ( x ) ;
// D i s p l a y i n g t h e f i n a l r e s u l t //

Scilab code Exa 2.3.c decimal conversion


1 // e x a m p l e 2 . 3 ( c ) //
2 clc
3 // c l e a r s t h e command window //
4 clear
5 // c l e a r s //
6 p =1;
7 // i n i t i a l i s i n g //

18

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

q =1;
z =0;
b =0;
w =0;
f =0;
// b i n= i n p u t (
E n t e r t h e b i n a r y no t o be
converted to i t s decimal e q u i v a l e n t :
)
// a c c e p t i n g t h e b i n a r y i n p u t from u s e r //
bin =1001.0101;
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 and 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)
// Loop t o t a k e t h e b i n a r y b i t s o f i n t e g e r 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 i y i n g t h e b i t s o f i n t e g e r w i t h t h e i r
p o s i t i o n v a l u e s and a d d i n g //
c = m -1;
f = f + b (1 , m ) *(2^ c ) ;
end
while ( d >0)
// Loop t o t a k e t h e b i n a r y b i t s o f d e c i m a l 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
19

42 for n =1: p -1
43 // m u l t i p l i y i n g t h e
44
45
46
47
48
49
50
51
52
53

b i t s o f decimal with t h e i r
p o s i t i o n v a l u e s and a d d i n g //
z = z + w (1 , n ) *(0.5) ^(11 - n ) ;
end
z = z *10000;
// r o u n d i n g o f t o 4 d e c i m a l v a l u e s //
z = round ( z ) ;
z = z /10000;
x=f+z;
disp ( The 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
g i v e n i s );
disp ( x ) ;
// D i s p l a y i n g t h e f i n a l r e s u l t //

Scilab code Exa 2.3.d decimal representation


// e x a m p l e 2 . 3 ( d ) //
clc
// c l e a r s t h e command window //
clear
// c l e a r s //
p =1;
// i n i t i a l i s i n g //
q =1;
z =0;
b =0;
w =0;
f =0;
// b i n= i n p u t (
E n t e r t h e b i n a r y no t o be
converted to i t s decimal e q u i v a l e n t :
)
14 // a c c e p t i n g t h e b i n a r y i n p u t from u s e r //
15 bin =0.10101;
1
2
3
4
5
6
7
8
9
10
11
12
13

20

16 d = modulo ( bin ,1) ;


17 // s e p a r a t i n g t h e d e c i m a l p a r t and t h e i n t e g e r p a r t //
18 d = d *10^10;
19 a = floor ( bin ) ;
20 // r e m o v i n g t h e d e c i m a l p a r t //
21 while ( a >0)
22 // Loop t o t a k e t h e b i n a r y b i t s o f i n t e g e r i n t o a
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

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 i y i n g t h e b i t s o f i n t e g e r w i t h t h e i r
p o s i t i o n v a l u e s and a d d i n g //
c = m -1;
f = f + b (1 , m ) *(2^ c ) ;
end
while ( d >0)
// Loop t o t a k e t h e b i n a r y b i t s o f d e c i m a l 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
// m u l t i p l i y i n g t h e b i t s o f d e c i m a l w i t h t h e i r
p o s i t i o n v a l u e s and a d d i n g //
z = z + w (1 , n ) *(0.5) ^(11 - n ) ;
end
z = z *10000;
// r o u n d i n g o f t o 4 d e c i m a l v a l u e s //
z = round ( z ) ;
z = z /10000;
21

50 x = f + z ;
51 disp ( The D e c i m a l e q u i v a l e n t

g i v e n i s );
52 disp ( x ) ;
53 // D i s p l a y i n g t h e f i n a l

o f t h e B i n a r y number

r e s u l t //

Scilab code Exa 2.4 binary conversion


1 // e x a m p l e 2 . 4 / /
2 ans = dec2bin (13)
3 // c o n v e r s i o n o f d e c i m a l number t o b i n a r y //
4 disp ( ans )
5 // a n s w e r i n b i n a r y form //

Scilab code Exa 2.5 conversion


// e x a m p l e 2 . 5 / /
clc
// c l e a r s t h e command window //
clear
// c l e a r s a l l t h e v a r i a b l e s //
q =0;
b =0;
s =0;
// a=i n p u t ( E n t e r t h e d e c i m a l no t o be c o n v e r t e d t o
i t s binary equivalent :
) ;
10 // a c c e p t i n g t h e d e c i m a l i n p u t from u s e r //
1
2
3
4
5
6
7
8
9

22

11 a =0.65625;
12 d = modulo ( a ,1) ;
13 // s e p a r a t i n g t h e d e c i m a l p a r t and t h e i n t e g e r p a r t //
14 a = floor ( a ) ;
15 // r e m o v i n g t h e d e c i m a l p a r t //
16 while ( a >0)
17 // t a k i n g i n t e g e r p a r t i n t o a m a t r i x and c o n v e r t t o
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

e q u i v a l e n t b i n a r y //
x = modulo ( a ,2) ;
b = b + (10^ q ) * x ;
a = a /2;
a = floor ( a ) ;
q = q +1;
end
for i =1:10
// For v a l u e s a f t e r d e c i m a l p o i n t c o n v e r t i n g t o
b i n a r y //
d = d *2;
q = floor ( d ) ;
s = s + q /(10^ i ) ;
if d >=1 then
d = d -1;
end
end
k=b+s;
disp ( The b i n a r y e q u i v a l e n t o f t h e g i v e n d e c i m a l
number i s = ) ;
disp ( k ) ;
// d i s p l a y i n g t h e f i n a l r e s u l t .

Scilab code Exa 2.6.a dec to bin


1

// e x a m p l e 2 . 6 ( a ) //
23

2
3
4
5
6
7
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

clc
// c l e a r s t h e command window //
clear
// c l e a r s a l l t h e v a r i a b l e s //
q =0;
b =0;
s =0;
// a=i n p u t ( E n t e r t h e d e c i m a l no t o be c o n v e r t e d t o
i t s binary equivalent :
) ;
// a c c e p t i n g t h e d e c i m a l i n p u t from u s e r //
a =25.5;
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 and t h e i n t e g e r p a r t //
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)
// t a k i n g i n t e g e r p a r t i n t o a m a t r i x and c o n v e r t t o
e q u i v a l e n t b i n a r y //
x = modulo ( a ,2) ;
b = b + (10^ q ) * x ;
a = a /2;
a = floor ( a ) ;
q = q +1;
end
for i =1:10
// For v a l u e s a f t e r d e c i m a l p o i n t c o n v e r t i n g t o
b i n a r y //
d = d *2;
q = floor ( d ) ;
s = s + q /(10^ i ) ;
if d >=1 then
d = d -1;
end
end
k=b+s;
disp ( The b i n a r y e q u i v a l e n t o f t h e g i v e n d e c i m a l
number i s = ) ;
disp ( k ) ;
24

36

// d i s p l a y i n g t h e f i n a l

r e s u l t //

Scilab code Exa 2.6.b dec to bin


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

// e x a m p l e 2 . 6 ( b ) //
clc
// c l e a r s t h e command window //
clear
// c l e a r s a l l t h e v a r i a b l e s //
q =0;
b =0;
s =0;
// a=i n p u t ( E n t e r t h e d e c i m a l no t o be c o n v e r t e d t o
i t s binary equivalent :
) ;
// a c c e p t i n g t h e d e c i m a l i n p u t from u s e r //
a =10.625;
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 and t h e i n t e g e r p a r t //
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)
// t a k i n g i n t e g e r p a r t i n t o a m a t r i x and c o n v e r t t o
e q u i v a l e n t b i n a r y //
x = modulo ( a ,2) ;
b = b + (10^ q ) * x ;
a = a /2;
a = floor ( a ) ;
q = q +1;
end
for i =1:10
// For v a l u e s a f t e r d e c i m a l p o i n t c o n v e r t i n g t o
b i n a r y //
d = d *2;
25

27
28
29
30
31
32
33
34

q = floor ( d ) ;
s = s + q /(10^ i ) ;
if d >=1 then
d = d -1;
end
end
k=b+s;
disp ( The b i n a r y e q u i v a l e n t o f t h e g i v e n d e c i m a l
number i s = ) ;
35 disp ( k ) ;
36 // d i s p l a y i n g t h e f i n a l r e s u l t .

Scilab code Exa 2.6.c dec to bin


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// e x a m p l e 2 . 6 ( c ) //
clc
// c l e a r s t h e command window //
clear
// c l e a r s a l l t h e v a r i a b l e s //
q =0;
b =0;
s =0;
// a=i n p u t ( E n t e r t h e d e c i m a l no t o be c o n v e r t e d t o
i t s binary equivalent :
) ;
// a c c e p t i n g t h e d e c i m a l i n p u t from u s e r //
a =0.6875;
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 and t h e i n t e g e r p a r t //
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)
// t a k i n g i n t e g e r p a r t i n t o a m a t r i x and c o n v e r t t o
e q u i v a l e n t b i n a r y //
26

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

x = modulo ( a ,2) ;
b = b + (10^ q ) * x ;
a = a /2;
a = floor ( a ) ;
q = q +1;
end
for i =1:10
// For v a l u e s a f t e r d e c i m a l p o i n t c o n v e r t i n g t o
b i n a r y //
d = d *2;
q = floor ( d ) ;
s = s + q /(10^ i ) ;
if d >=1 then
d = d -1;
end
end
k=b+s;
disp ( The b i n a r y e q u i v a l e n t o f t h e g i v e n d e c i m a l
number i s = ) ;
disp ( k ) ;
// d i s p l a y i n g t h e f i n a l r e s u l t //

Scilab code Exa 2.8.a ones complement


1 // e x a m p l e 2 . 8 ( a ) //
2 // one s complement o f b i n a r y number //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // 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 //
7 x = bin2dec ( 0 1 0 0 1 1 1 0 0 1 )
8 // e n t e r i n g t h e d a t a i n b i n a r y form //
9 ans = dec2bin ( bitcmp (x ,10) )

27

10
11

disp ( ans ) ;
// r e s u l t w i l l be d i s p l a y e d //

Scilab code Exa 2.8.b ones complement of unsigned no


1 // e x a m p l e 2 . 8 ( b ) //
2 // one s complement o f b i n a r y number //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // 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 //
7 x = bin2dec ( 1 1 0 1 1 0 1 0 )
8 // e n t e r i n g t h e d a t a i n b i n a r y form //
9 ans = dec2bin ( bitcmp (x ,8) )
10 disp ( ans ) ;
11 // r e s u l t w i l l be d i s p l a y e d //

Scilab code Exa 2.9.a ones comp


1 // e x a m p l e 2 . 9 ( a ) //
2 // r e p r e s e n t a t i o n i n 1 s complement form //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // 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 //
7 x =7
8 // x=+7//y=x //
9 xb = dec2bin (7)

28

10
11
12
13
14
15
16
17
18
19
20
21

// xb means b i n a r y c o n v e r s i o n o f x t o i t s one s
complement form //
xc = dec2bin ( bitcmp (7 ,4) )
// xc means c o n v e r s i o n o f y i n i t s one s complement
form //
disp ( d i s p l a y i n g r e s u l t o f +7 and 7 i n o n e s
complement form )
disp ( x )
printf ( = )
disp ( xb )
// d i s p l a y i n g a n s w e r i n one s complement form //
disp ( - x )
printf ( = )
disp ( xc )
// a n s w e r i n one s complement form //

Scilab code Exa 2.9.b ones complement of signed no


1 // e x a m p l e 2 . 9 ( b ) //
2 // r e p r e s e n t a t i o n i n 1 s complement form //
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 t h e e x i s t i n g v a r i a b l e s //
7 x =8
8 // x=+8//y=x //
9 xb = dec2bin (8)
10 // xb means b i n a r y c o n v e r s i o n o f x t o i t s one s

complement form //
11 xc = dec2bin ( bitcmp (8 ,5) )
12 // xc means c o n v e r s i o n o f y i n
13

form //
disp ( x )
29

i t s one s complement

14
15
16
17
18
19
20

printf ( = )
disp ( xb )
// d i s p l a y i n g a n s w e r i n one s complement form //
disp ( - x )
printf ( = )
disp ( xc )
// a n s w e r i n one s complement form //

Scilab code Exa 2.9.c ones complement of signed no


1 // e x a m p l e 2 . 9 ( c ) //
2 // r e p r e s e n t a t i o n i n 1 s complement form //
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 t h e e x i s t i n g v a r i a b l e s //
7 x =15
8 // x=+15//y=x //
9 xb = dec2bin (15)
10 // xb means b i n a r y c o n v e r s i o n o f x t o i t s one s

complement form //
11 xc = dec2bin ( bitcmp (15 ,5) )
12 // xc means c o n v e r s i o n o f y i n
13
14
15
16
17
18
19
20

i t s one s complement

form //
disp ( x )
printf ( = )
disp ( xb )
// d i s p l a y i n g a n s w e r i n one s complement form //
disp ( - x )
printf ( = )
disp ( xc )
// a n s w e r i n one s complement form //

30

Scilab code Exa 2.10.a twos complement


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// e x a m p l e 2 . 1 0 ( a ) //
// f i n d 2 s complement o f b i n a r y number //
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 =01001110
// t h e number //
xd = bin2dec ( 0 1 0 0 1 1 1 0 )
// 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 //
xc = bitcmp ( xd ,8)
// one s complement o f t h e number //
xp = xc +1
xc1 = dec2bin ( xp )
// 2 s complement o f t h e number //
disp ( 2 s complement o f 0 1 0 0 1 1 1 0 i s : )
disp ( xc1 )
// a n s w e r i n 2 s complement form //

Scilab code Exa 2.10.b twos complement of binary no


1 // e x a m p l e 2 . 1 0 ( b ) //
2 // f i n d 2 s complement o f b i n a r y number //
3 clc
4 // c l e a r s t h e window //
5 clear

31

6
7
8
9
10
11
12
13
14
15
16
17
18

// 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 =00110101
// t h e number //
xd = bin2dec ( 0 0 1 1 0 1 0 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 //
xc = bitcmp ( xd ,8)
// one s complement o f t h e number //
xp = xc +1
xc1 = dec2bin ( xp )
// 2 s complement o f t h e number //
disp ( 2 s complement o f 0 0 1 1 0 1 0 1 i s : )
disp ( xc1 )
// a n s w e r i n 2 s complement form //

Scilab code Exa 2.11.a complement


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// e x a m p l e 2 . 1 1 ( a ) //
// f i n d 2 s complement o f b i n a r y number //
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 =01100100
// t h e number //
xd = bin2dec ( 0 1 1 0 0 1 0 0 )
// 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 //
xc = bitcmp ( xd ,8)
// one s complement o f t h e number //
xp = xc +1
xc1 = dec2bin ( xp )
// 2 s complement o f t h e number //
disp ( 2 s complement o f 0 1 1 0 0 1 0 0 i s : )
disp ( xc1 )
32

18

// a n s w e r i n 2 s complement form //

Scilab code Exa 2.11.b complement


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// e x a m p l e 2 . 1 1 ( b ) //
// f i n d 2 s complement o f b i n a r y number //
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 =10010010
// t h e number //
xd = bin2dec ( 1 0 0 1 0 0 1 0 )
// 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 //
xc = bitcmp ( xd ,8)
// one s complement o f t h e number //
xp = xc +1
xc1 = dec2bin ( xp )
// 2 s complement o f t h e number //
disp ( 2 s complement o f 1 0 0 1 0 0 1 0 i s : )
disp ( xc1 )
// a n s w e r i n 2 s complement form //

Scilab code Exa 2.11.c complement


1 // e x a m p l e 2 . 1 1 ( c ) //
2 // f i n d 2 s complement o f b i n a r y number //
3 clc
4 // c l e a r s t h e window //

33

5
6
7
8
9
10
11
12
13
14
15
16
17
18

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 =11011000
// t h e number //
xd = bin2dec ( 1 1 0 1 1 0 0 0 )
// 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 //
xc = bitcmp ( xd ,8)
// one s complement o f t h e number //
xp = xc +1
xc1 = dec2bin ( xp )
// 2 s complement o f t h e number //
disp ( 2 s complement o f 1 1 0 1 1 0 0 0 i s : )
disp ( xc1 )
// a n s w e r i n 2 s complement form //

Scilab code Exa 2.11.d twos complement of binary number


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// e x a m p l e 2 . 1 1 ( d ) //
// f i n d 2 s complement o f b i n a r y number //
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 =01100111
// t h e number //
xd = bin2dec ( 0 1 1 0 0 1 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 //
xc = bitcmp ( xd ,8)
// one s complement o f t h e number //
xp = xc +1
xc1 = dec2bin ( xp )
// 2 s complement o f t h e number //
disp ( 2 s complement o f 0 1 1 0 0 1 1 1 i s : )
34

17
18

disp ( xc1 )
// a n s w e r i n 2 s complement form //

Scilab code Exa 2.13.a addition


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// e x a m p l e 2 . 1 3 ( a ) //
// a d d i t i o n o f b i n a r y number //
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s 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 )
// 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 //
y = bin2dec ( 1 1 0 0 )
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 ( t h e a d d i t i o n o f g i v e n numbers i s : )
disp ( a )
// a n s w e r i n b i n a r y form //

Scilab code Exa 2.13.b addition of binary numbers


1 // e x a m p l e 2 . 1 3 ( b ) //
2 // a d d i t i o n o f b i n a r y number //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear

35

6
7
8
9
10
11
12
13
14
15
16

// c l e a r s 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 ( 0 1 0 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 //
y = bin2dec ( 1 1 1 1 )
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 ( t h e a d d i t i o n o f g i v e n numbers i s : )
disp ( a )
// a n s w e r i n b i n a r y form //

Scilab code Exa 2.14 addition of 4 binary numbers


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

// e x a m p l e 2 . 1 4 / /
// a d d i t i o n o f b i n a r y numbers //
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s 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 ( 0 1 1 0 1 0 1 0 )
// x i s t h e f i r s t number i n a d d i t i o n //
// 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 //
y = bin2dec ( 0 0 0 0 1 0 0 0 )
// y i s t h e s e c o n d number i n a d d i t i o n //
t = bin2dec ( 1 0 0 0 0 0 0 1 )
// t i s t h e t h i r d number i n a d d i t i o n //
k = bin2dec ( 1 1 1 1 1 1 1 1 )
// k i s t h e f o u r t h number we have t o end //
z=x+y+t+k
// 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 //
36

20
21
22

disp ( t h e a d d i t i o n o f g i v e n numbers i s : )
disp ( a )
// a n s w e r i n b i n a r y form //

Scilab code Exa 2.15 subtraction of binary numbers


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// e x a m p l e 2 . 1 5 / /
// s u b t r a c t i o n o f two b i n a r y number //
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s t h e e x i s t i n g v a r i a b l e s //
x = bin2dec ( 1 0 1 1 )
// x i s t h e minuend //
// 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 //
y = bin2dec ( 0 1 1 0 )
// y i s t h e s u b t r a h e n d //
z =x - y
// s u b t r a c t i o n //
disp ( t h e s u b t r a c t i o n o f g i v e n numbers i s : )
ans = 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 ( ans )
// a n s w e r i n b i n a r y form //

Scilab code Exa 2.16 multiplication of binary numbers


1
2

// e x a m p l e 2 . 1 6 / /
// m u l t i p l i c a t i o n i n b i n a r y form //
37

3
4
5
6
7
8
9
10
11
12
13
14
15
16

clc
// c l e a r s t h e s c r e e n //
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 = bin2dec ( 1 0 0 1 )
// f i r s t number t o be m u l t i p l i e d i s x //
// 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 //
y = bin2dec ( 1 1 0 1 )
// s e c o n d number t o be m u l t i p l i e d i s y //
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 ( t h e m u l t i p l i c a t i o n o f g i v e n numbers r e s u l t s i n
: )
17 disp ( a )
18 // a n s w e r i n b i n a r y number //

Scilab code Exa 2.17 division of binary numbers


1
2
3
4
5
6
7
8
9
10
11
12
13

// e x a m p l e 2 . 1 7 / /
// d i v i s i o n i n b i n a r y //
clc
// c l e a r s t h e window //
clear
// c l e a r s 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 0 1 0 1 )
// x i s t h e f i r s t number //
// 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 //
y = bin2dec ( 1 0 0 1 )
// y i s t h e s e c o n d number w/ c i s t o be d i v i d e d //
z=x/y
// d i v i s i o n //
38

14 a = dec2bin ( z )
15 // 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 //
16 disp ( t h e d i v i s i o n o f g i v e n numbers r e s u l t s
17 disp ( a )
18 // a n s w e r i n b i n a r y form //

Scilab code Exa 2.21 decimal to octal conversion


1 // e x a m p l e 2 . 2 1 / /
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 x =247
7 // d e c i m a l t o o c t a l c o n v e r s i o n //
8 a = dec2oct ( x )
9 disp ( t h e o c t a l c o n v e r s i o n o f g i v e n no i s : )
10 disp ( a )
11 // a n s w e r i n o c t a l form //

Scilab code Exa 2.22 convert octal to binary


1 // e x a m p l e 2 . 2 2 / /
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 // o c t a l t o b i n a r y c o n v e r s i o n //
7 y = oct2dec ( 736 )

39

in : )

8 // o c t a l t o d e c i m a l c o n v e r s i o n //
9 a = dec2bin ( y )
10 // 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 //
11 disp ( b i n a r y c o n v e r s i o n o f g i v e n no i s : )
12 disp ( a )
13 // a n s w e r i n b i n a r y form //

Scilab code Exa 2.23 binary to octal


1 // e x a m p l e 2 . 2 3 / /
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 // b i n a r y t o o c t a l c o n v e r s i o n //
7 y = bin2dec ( 1 0 0 1 1 1 0 )
8 // 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 //
9 a = dec2oct ( y )
10 // d e c i m a l t o o c t a l c o n v e r s i o n //
11 disp ( o c t a l r e p r e s e n t a t i o n o f g i v e n no i s
12 disp ( a )
13 // a n s w e r i n o c t a l form //

Scilab code Exa 2.26 addition of octal numbers


1 // e x a m p l e 2 . 2 6 / /
2 // a d d i t i o n o f o c t a l numbers //
3 clc
4 // c l e a r s t h e s c r e e n //

40

: )

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

clear
// c l e a r s 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 = oct2dec ( 23 )
// o c t a l t o d e c i m a l c o n v e r s i o n //
y = oct2dec ( 67 )
z=x+y
// a d d i t i o n //
a = dec2oct ( z )
// d e c i m a l t o o c t a l c o n v e r s i o n //
b = 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 g i v e n no i s o c t a l form i s )
disp ( a )
// a n s w e r i n o c t a l form //
disp ( a d d i t i o n o f g i v e n numbers i n b i n a r y form i s : )
disp ( b )
// a n s w e r i n b i n a r y form //

Scilab code Exa 2.27.a addition of octal numbers


1
2
3
4
5
6
7
8
9
10
11
12
13

// e x a m p l e 2 . 2 7 ( a ) //
// s u b t r a c t i o n o f o c t a l numbers //
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s 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 = oct2dec ( 53 )
// o c t a l t o d e c i m a l c o n v e r s i o n //
y = oct2dec ( 37 )
z =x - y
// s u b t r a c t i o n //
a = dec2oct ( z )
// d e c i m a l t o o c t a l c o n v e r s i o n //
41

14 b = dec2bin ( z )
15 // 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 //
16 disp ( r e s u l t o f s u b t r a c t i o n o f g i v e n numbers i n

o c t a l form i s : )
disp ( a )
// a n s w e r i n o c t a l form //
disp ( r e s u l t o f s u b t r a c t i o n o f g i v e n numbers i n
b i n a r y form i s : )
20 disp ( b )
21 // a n s w e r i n b i n a r y form //
17
18
19

Scilab code Exa 2.27.b addition of OCTAL numbers


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

// e x a m p l e 2 . 2 7 ( b ) //
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s 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 = oct2dec ( 26 )
// o c t a l t o d e c i m a l c o n v e r s i o n //
y = oct2dec ( 75 )
z =x - y
// s u b t r a c t i o n //
t = z *( -1)
t1 = bitcmp (t ,8)
// 1 s complement //
t2 = t1 +1
// 2 s c o m p l i m e n t //
a = dec2bin ( t2 )
// 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 n s w e r i n 2 s c o m p l i m e n t form : )
disp ( a )
// a n s w e r i n 2 s complement form //
42

Scilab code Exa 2.30 convert hexadecimal to binary


1 // e x a m p l e 2 . 3 0 / /
2 // h e x a 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 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
7 x = hex2dec ( 29FA )
8 // h e x a d e c i m a l t o d e c i m a l c o n v e r s i o n //
9 a = dec2bin ( x )
10 // 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 //
11 disp ( c o n v e r s i o n o f h e x a d e c i m a l g i v e n no t o

b i n a r y form i s : )
12 disp ( a )
13 // a n s w e r i n b i n a r y form //

Scilab code Exa 2.31 binary to hexadecimal number


1 // e x a m p l e 2 . 3 1 / /
2 // c o n v e r s i o n o f b i n a r y t o h e x a d e c i m a l //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
7 x = bin2dec ( 1 0 1 0 0 1 1 0 1 0 1 1 1 1 )
8 // 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 //

43

its

9 a = dec2hex ( x )
10 // 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 //
11 disp ( c o n v e r s i o n o f g i v e n b i n a r y number t o
12
13

its

h e x a d e c i m a l form i s : )
disp ( a )
// a n s w e r i n h e x a d e c i m a l form //

Scilab code Exa 2.33 hexadecimal to octal number


1 // e x a m p l e 2 . 3 3 / /
2 // c o n v e r s i o n h e x a d e c i m a l number t o o c t a l number //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
7 x = hex2dec ( A72E )
8 // h e x a d e c i m a l t o d e c i m a l c o n v e r s i o n //
9 a = dec2oct ( x )
10 // d e c i m a l t o o c t a l c o n v e r s i o n //
11 disp ( c o n v e r s i o n o f g i v e n h e x a d e c i m a l no t o i t s

o c t a l form r e s u l t s i n : )
12 disp ( a )
13 // a n s w e r i n o c t a l form //

Scilab code Exa 2.35 addition of hexadecimal numbers


1 // e x a m p l e 2 . 3 5 / /
2 // a d d i t i o n o f h e x a d e c i m a l number //
3 clc

44

// c l e a r s t h e s c r e e n //
clear
// c l e a r s 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 = hex2dec ( 7F )
// h e x a d e c i m a l t o d e c i m a l c o n v e r s i o n //
y = hex2dec ( BA )
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 g i v e n h e x a d e c i m a l numbers r e s u l t s
in : )
15 disp ( a )
16 // a n s w e r i n h e x a d e c i m a l form //
4
5
6
7
8
9
10
11
12
13
14

Scilab code Exa 2.36.a subtraction of hexadecimal numbers


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// e x a m p l e 2 . 3 6 ( a ) //
// s u b t r a c t i o n o f h e x a d e c i m a l number //
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s 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 = hex2dec ( 3F )
// h e x a d e c i m a l t o d e c i i m a l c o n v e r s i o n //
y = hex2dec ( 5C )
z =x - y
// s u b t r a c t i o n //
t = z * -1
t1 = dec2hex ( t )
// a n s w e r i n h e x a d e c i m a l form ( modulus ) //
t2 = bitcmp (t ,8)
// complement //
45

17 t3 = t2 +1
18 // 2 s complement //
19 a = dec2bin ( t3 )
20 // a n s w e r i n 2 s complement form
21 disp ( r e s u l t o f s u b t r a c t i o n i n 2 s c o m p l i m e n t form

is : )
22 disp ( a )

Scilab code Exa 2.36.b subtraction of hexadecimal numbers


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

// e x a m p l e 2 . 3 6 ( b ) //
// s u b t r a c t i o n o f h e x a d e c i m a l numbers //
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s 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 = hex2dec ( C0 )
// h e x a d e c i m a l t o d e c i m a l c o n v e r s i o n //
y = hex2dec ( 7A )
z =x - y
// s u b t r a c 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 //
b = 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 n s w e r i n h e x a d e c i m a l form i s : )
disp ( a )
// a n s w e r i n h e x a d e c i m a l form //
disp ( a n s w e r i n b i n a r y form i s : )
disp ( b )
// a n s w e r i n b i n a r y number //

46

Chapter 3
Semiconductor devices
switching mode operation

Scilab code Exa 3.3 response of transistor inverter


// e x a m p l e 3 . 3 / /
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s a l r e a d y e x i s t i n g v a r i b a l e s //
a =10;
// i n p u t v o l t a g e ( i n v o l t s ) //
b =.7;
// t r a n s i s t o r v o l t a g e ( s a t u r a t i o n v o l t a g e ) //
c =5;
// r e s i s t o r b /w i n p u t v o l t a g e and t h e t r a n s i s t o r //
d =10;
// i n p u t v o l t a g e from c o l l e c t o r s i d e //
e =0.1;
// t r a n s i s t o r v o l t a g e ( s a t u r a t i o n v o l t a g e from
c o l l e c t o r s i d e ) //
16 f =2;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

47

17 // r e s i s t o r i n k i l o ohm//
18 g =30;
19 h = -10;
20 // i n p u t v o l t a g e from e m i t t e r s i d e //
21 I =( a - b ) / c ;
22 // b a s e c u r r e n t o f t r a n s i s t o r from g i v e n
23 disp ( t h e b a s e c u r r e n t o f g i v e n c i r c u i t
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

f i g u r e //
i s ( i n mA) :

)
disp ( I )
// b a s e c u r r e n t i s i n mA//
K =( d - e ) / f
// c o l l e c t o r c u r r e n t o f t r a n s i s t o r from g i v e n f i g u r e
//
disp ( t h e c o l l e c t o r c u r r e n t o f g i v e n c i r c u i t i s ( i n
mA) : )
disp ( K )
// c o l l e c t o r c u r r e n t i n mA( s a t u r a t i o n c u r r e n t ) //
L=K/g
disp ( b a s e c u r r e n t r e q u i r e d f o r t h e t r a n s i s t o r t o be
i n s a t u r a t i o n i s ( i n mA) : )
disp ( L )
// c u r r e n t i n mA//
M =( h - b ) / c
disp ( t h e b a s e c u r r e n t i s ( i n mA) : )
disp ( M )
// b a s e c u r r e n t i n mA//

Scilab code Exa 3.4.a output voltage of JFET


1 // e x a m p l e 3 . 4 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear

48

// c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
disp ( when t h e i n p u t v o l t a g e = 5V, t h e JFET i s
o p e n i n g a t p o i n t A, where I (D) =0 and V( 0 )=V(DD)
=20V )
7 disp ( t h i s c o r r e s p o n d s t o t h e s w i t c h i n OFF s t a t e )
5
6

Scilab code Exa 3.4.b output voltage of JFET


1 // e x a m p l e 3 . 4 ( b ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s t h e command window //
6 disp ( when V( i ) =0V, t h e JFET i s

operating at point B
, where I (D) =3.8mA and V( o ) =1V )
7 disp ( t h i s c o r r e s p o n d s t o t h e s w i t c h i n ON s t a g e )
8 // t h e a n s w e r s have b e e n t a k e n d i r e c t l y from t h e
f i g u r e //

Scilab code Exa 3.5.a output characateristics of a MOSFET


1 // e x a m p l e 3 . 5 ( a ) //
2 clc
3 // c l e a r s t h e window //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( when V( i ) =0 , t h e t r a n s i s t o r i s c u t o f f

because
t h e v o l t a g e b e t w e e n t h e g a t e and t h e s o u r c e i s

49

below the t h r e s h o l d v o l t a g e . C o r r e s p o n d i n g l y the


o u t p u t v o l t a g e V( 0 ) =5V( p o i n t (N) a s i n f i g u r e ) )
7 // a n s w e r a c c o r d i n g t o t h e c u t s o f l o a d l i n e //

Scilab code Exa 3.5.b output voltage for MOSFET


1 // e x a m p l e 3 . 5 ( b ) //
2 clc
3 // c l e a r s t h e window //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( when V( i ) =5V, t h e t r a n s i s t o r i s o p e r a t i n g a t
7

p o i n t M and V( o ) =0 )
disp ( t h i s c o r r e s p o n d s t o ON s t a g e ! )

Scilab code Exa 3.7.a output voltage for identical set of transistors
1 // e x a m p l e 3 . 7 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s e x i s t i n g v a r i a b l e s //
6 disp ( when V( i ) =0 , t h e t r a n s i s t o r T ( 1 )

at point B )
7 t =5;
8 // i n p u t v o l t a g e a s g i v e n i n q u e s t i o n //
9 x =0;
10 V =t - x ;
11 // o u t p u t v o l t a g e i n v o l t s //

50

is operating

12
13

disp ( h e r e V( o ) ( i n v o l t s )= )
disp ( V )

Scilab code Exa 3.7.b output voltage in identical transistors for input
voltage 5V
1 // e x a m p l e 3 . 7 ( b ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( when V( i ) =5V, t h e t r a n s i s t o r T ( 1 )

is operating

at point C )
7 V =0;
8 disp ( o u t p u t v o l t a g e i n v o l t s = )
9 disp ( V )
10 // a l l t h e o u t c o m e s a r e a s p e r t h e d i a g r a m //

51

Chapter 4
Digital Logic Families

Scilab code Exa 4.1.a.i calculate fan out when all inputs are high
1 // e x a m p l e 4 . 1 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( a s g i v e n low l e v e l , V( o ) =0.2V and h i g h l e v e l ,
7
8
9
10
11
12
13
14
15
16
17

V( 1 ) =5V )
disp ( c a s e 1 , when a l l t h e i n p u t s a r e HIGH )
// i n t h i s c a s e b o t h d i o d e s w i l l be c o n d u c t i n g and
t r a n s i s t o r w i l l be i n s a t u r a t i o n //
a =0.7+0.7+0.8;
//V( p ) //
b =5;
// h i g h l e v e l v o l t a g e i n v o l t s //
c =5;
// r e s i s t o r i n Kohms //
d =0.8;
// v o l t a g e b e t w e e n b a s e and e m i t t e r i n v o l t s //
e =( b - a ) / c ;
52

18 // I ( 1 ) //
19 f = d / c ;
20 // I ( 2 ) //
21 i =e - f ;
22 // w r i t i n g
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

k i r c h o f f s c u r r e n t law a t t h e b a s e o f
t r a n s i s t o r //
g =0.2;
// v o l t a g e b e t w e e n c o l l e c t o r and e m i t t e r i n
s a t u r a t i o n ( i n v o l t s ) //
h =2.2;
// r e s i s t a n c e o f c o l l e c t o r i n Kohms //
j =( b - g ) / h ;
// c o l l e c t o r c u r r e n t w i t h o u t l o a d g a t e c o n n e c t e d //
disp ( I ( 1 ) i n mA: )
disp ( e )
disp ( I ( 2 ) i n mA: )
disp ( f )
disp ( c o l l e c t o r c u r r e n t ( i n mA) : )
disp ( j )
k =30;
// h (FE) //
s=k*i;
if (s > j )
disp ( t r a n s i s t o r i s i n s a t u r a t i o n mode )
disp ( f a n o u t i s g i v e n by I ( c )<=h (FE) I (B) )
end

Scilab code Exa 4.1.a.ii calculate fan out for DTL NAND gate when atleast
one input is LOW
1 // e x a m p l e 4 . 1 . a ( i i ) //
2 clc
3 // c l e a r s t h e s c r e e n //

53

4
5
6
7
8
9
10
11
12
13
14
15
16

17

clear
// c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
// f o r DTL NAND g a t e c a l c u l a t e f a n o u t //
disp ( c a s e I I , i f a t l e a s t one o f t h e i n p u t s i s LOW
)
v =0.2+0.7;
m =0.6+0.6+0.5;
// min v o l t a g e f o r b o t h d i o d e s and t r a n s i s t o r t o be
c o n d u c t i n g //
disp ( v )
disp ( min v o l t a g e f o r b o t h d i o d e s and t r a n s i s t o r t o
be c o n d u c t i n g : )
disp ( m )
if (v < m )
disp ( t r a n s i s t o r i s i n c u t o f f mode )
disp ( i f t h e l o a d g a t e s a r e c o n n e c t e d , t h e i n p u t
d i o d e s o f t h e l o a d g a t e s a r e non c o n d u c t i n g ,
which means t h e r e v e r s e s a t u r a t i o n c u r r e n t o f
t h e s e d i o d e s must be s u p p l i e d t h r o u g h t h e
c o l l e c t o r r e s i s t o r R( c ) , which w i l l p r o d u c e a
v o l t a g e d r o p a c r o s s R( c ) and c o n s e q u e n t l y t h e
o u t p u t v o l t a g e c o r r e s p o n d i n g t o HIGH s t a t e w i l l
be a l i t t l e l e s s t h a n V( c c ) . The maximum c u r r e n t
which can be s u p p l i e d by t h e g a t e w i l l depend
upon V(OH) . The f a n o u t i s d e t e r m i n e d on t h e
b a s i s o f maximum c u r r e n t . )
end

54

Chapter 5
Combinational Logic Design

Scilab code Exa 5.1 simplification of equation


1 // e x m a p l e 5 . 1 ( c ) //
2 // s i m p l i f i c a t i o n o f an e q u a t i o n //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
7 disp ( g i v e n=> Y=(A+BC) (B+C A) )
8 // g i v e n i n t h e q u e s t i o n //
9 disp ( on m u l t i p l i c a t i o n we g e t )
10 disp ( Y=AB+AC +BC )
11 disp ( on f u r t h e r s i m p l i f i c a t i o n we g e t )
12 disp ( BC+AC )
13 // a n s w e r a f t e r s i m p l i f i c a t i o n //
14 // a s p e r t h e o r e m 1 . 1 9 g i v e n i n t h e q u e s t i o n //

55

Scilab code Exa 5.2 conversion to canonical SOP form


1 // e x a m p l e 5 . 2 / /
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 // c o n v e r s i o n o f g i v e n e q u a t i o n t o i t s c a n o n i c a l SOP
7
8
9
10
11
12
13

form //
disp ( g i v e n=> Y=(AB+AC +BC) )
disp ( on s o l v i n g )
disp ( Y=AB(C+C )+AC (B+B )+BC(A+A ) )
disp ( Y=ABC+ABC +ABC +AB C +ABC+A BC )
disp ( Y=ABC+ABC +AB C +A BC )
// u s i n g t h e o r e m 1 . 5 / /
// r e s u l t //

Scilab code Exa 5.3 conversion to canonical POS form


1 // e x a m p l e 5 . 3 / /
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 // c o n v e r s i o n o f g i v e n e q u a t i o n t o i t s c a n o n i c a l POS
7
8
9
10
11
12

form //
disp ( g i v e n=> Y=(A+B) (A+C) (B+C ) )
disp ( on s o l v i n g )
disp ( Y=(A+B+CC ) (A+BB +C) (AA +B+C ) )
disp ( Y=(A+B+C) (A+B+C ) (A+C+B) (A+C+B ) (A+B+C ) (A
+B+C ) )
// u s i n g t h e o r e m 1 . 1 0 / /
disp ( Y=(A+B+C) (A+B+C ) (A+B +C) (A +B+C ) )
56

13
14

// u s i n g t h e o r e m 1 . 6 / /
// r e s u l t //

57

Chapter 6
Combinational Logic Design
using MSI circuits

Scilab code Exa 6.1 boolean equation using 8 to 1 mux


1 // e x a m p l e 6 . 1 / /
2 // b o o l e a n e q u a t i o n u s i n g 8 t o 1 mux//
3 clc ;
4 clear
5 a (1 ,1) =0
6 // t a k i n g i n p u t i n t h i s form 1 i f A, 0 i f
7
8
9
10
11
12
13
14
15
16

i f no A i n t h e term //
a (1 ,2) =1
a (1 ,3) =2
a (2 ,1) =2
a (2 ,2) =0
a (2 ,3) =0
a (3 ,1) =1
a (3 ,2) =1
a (3 ,3) =1
p =3;
for i =1:3
58

and 2

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
53
54

// f i n d i n g them i n t e r m s h e r e //
coun =0;
for j =1:3
if a ( i , j ) ==2 then
coun = coun +1
end
end
if coun == 2 then
p = p +3
else if coun ==1 then
p = p +1
end
end
end
n =4;
for m =4: p
for l =1:3
a ( m , l ) =0;
end
end
for i = 1: p
for j =1:3
if a ( i , j ) ==2 then
for k =1:3
a (n , k ) = a (i , k )
end
a ( i , j ) = 0;
a ( n , j ) =1;
n = n +1;
end
end
end
for h =1: p
f ( h ) =0
c =2;
for m =1:3
// f i n d i n g e q u i v l e n t //
59

55 end
56 end
57 disp ( t h e min t e r m s a r e d e c i m a l v a l u e s

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80

f o r the
minterms f ( h ) = f ( h ) + a ( h , m ) (2 c )
; c =c 1; : )
// d i s p l a y i n g t h e min t e r m s //
disp ( ABC )
disp ( a )
l =1
o (1 , l ) = f ( l ) ;
// r e m o v i n g t h e r e p e t a t i o n s i n m i n t e r m s //
for i =2: p
q =0;
for b =1: l
if o (1 , b ) == f ( i ) then
q =89 ;
end
end
if q ==0 then
o (1 , l +1) = f ( i ) ;
l = l +1;
q =0;
end
end
disp ( The f o l l o w i n g d a t a l i n e s a r e t o be g i v e n
1
and r e m a i n i n g s h o u l d be g i v e n
0 ) ;
// d i s p l a y i n g t h e d e c i m a l e q u i v l e n t o f m i n t e r m s //
disp ( o ) ;
disp ( For a 4
1 mux , we s h o u l d g i v e D0= C
, D1
=
1
, D2 = C and D3 = C w i t h A and
B as data s e l e c t o r i n p u t s );

60

Scilab code Exa 6.4.a subtraction


1
2
3
4
5
6
7
8
9
10

// exmple 6 . 4 ( a ) //
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
a =0;
b =0;
q =0;
// bb=i n p u t ( E n t e r t h e f i r s t no ( i n d e c i m a l ) :
) ;
// aa=i n p u t (
E n t e r t h e number from which f i r s t no
has to s u b t r a c t e d :
) ;
aa =9;
bb =5;
while ( aa >0)
// c o n v e r t i n g t h e i n p u t s i n t o b i n a r y numbers //
x = modulo ( aa ,2) ;
a = a + (10^ q ) * x ;
aa = aa /2;
aa = floor ( aa ) ;
q = q +1;
end
nn = a
q =0;
while ( bb >0)
x = modulo ( bb ,2) ;
b = b + (10^ q ) * x ;
bb = bb /2;

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 bb = floor ( bb ) ;
29 q = q +1;
30 end
31 printf ( \n The b i n a r y

e q u i v a l e n t o f f i r s t no i s
%f\n\n ,b ) ;
32 printf ( The b i n a r y e q u i v a l e n t o f s e c o n d no i s %f\n
\n ,a ) ;
61

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

for i =1:40
a1 ( i ) = modulo ( a ,10) ;
a = a /10;
a = round ( a ) ;
b1 ( i ) = modulo ( b ,10) ;
b = b /10;
b = round ( b ) ;
end
bro (1) =0;
for i =1:40
c1 ( i ) = a1 ( i ) - b1 ( i ) - bro
if c1 ( i ) == -1 then
bro ( i +1) = 1;
c1 ( i ) =1;
elseif c1 ( i ) == -2 then
bro ( i +1) = 1;
c1 ( i ) =0;
else
bro ( i +1) =0;
end
end
re =0;
format (
v ,18) ;
for i =1:40
re = re +( c1 ( i ) *(10^( i -1)
end
printf ( The d i f f e r e n c e o f g i v e n two
%f\n\n , re ) ;
q =1;
b =0;
f =0;
a = re ;
while ( a >0)
// c o n v e r t i n g t h e b i n a r y r e s u l t t o d e c i m a l
h e x a d e c i m a l //
r = modulo ( a ,10) ;
b (1 , q ) = r ;
a = a /10;
62

( i ) ;

) )
numbers i s

then to

69
70
71
72
73
74
75
76
77

a = floor ( a ) ;
q = q +1;
end
for m =1: q -1
c = m -1
f = f + b (1 , m ) *(2^ c ) ;
end
hex = dec2hex ( f ) ;
printf ( D i f f e r e n c e i n d e c i m a l n o t a t i o n i s %d\n\n
,f ) ;
78 printf ( D i f f e r e n c e i n h e x a d e c i m a l n o t a t i o n i s %s
\n , hex ) ;

Scilab code Exa 6.4.b subtraction


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// exmple 6 . 4 ( b ) //
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
a =0;
b =0;
q =0;
// bb=i n p u t ( E n t e r t h e f i r s t no ( i n d e c i m a l ) :
) ;
// aa=i n p u t (
E n t e r t h e number from which f i r s t no
has to s u b t r a c t e d :
) ;
aa =8;
bb =1;
while ( aa >0)
// c o n v e r t i n g t h e i n p u t s i n t o b i n a r y numbers //
x = modulo ( aa ,2) ;
a = a + (10^ q ) * x ;
63

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

aa = aa /2;
aa = floor ( aa ) ;
q = q +1;
end
nn = a
q =0;
while ( bb >0)
x = modulo ( bb ,2) ;
b = b + (10^ q ) * x ;
bb = bb /2;
bb = floor ( bb ) ;
q = q +1;
end
printf ( \n The b i n a r y e q u i v a l e n t o f f i r s t no i s
%f\n\n ,b ) ;
printf ( The b i n a r y e q u i v a l e n t o f s e c o n d no i s %f\n
\n ,a ) ;
for i =1:40
a1 ( i ) = modulo ( a ,10) ;
a = a /10;
a = round ( a ) ;
b1 ( i ) = modulo ( b ,10) ;
b = b /10;
b = round ( b ) ;
end
bro (1) =0;
for i =1:40
c1 ( i ) = a1 ( i ) - b1 ( i ) - bro ( i ) ;
if c1 ( i ) == -1 then
bro ( i +1) = 1;
c1 ( i ) =1;
elseif c1 ( i ) == -2 then
bro ( i +1) = 1;
c1 ( i ) =0;
else
bro ( i +1) =0;
end
64

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

end
re =0;
format (
v ,18) ;
for i =1:40
re = re +( c1 ( i ) *(10^( i -1) ) )
end
printf ( The d i f f e r e n c e o f g i v e n two numbers i s
%f\n\n , re ) ;
q =1;
b =0;
f =0;
a = re ;
while ( a >0)
// c o n v e r t i n g t h e b i n a r y r e s u l t t o d e c i m a l t h e n t o
h e x a d e c i m a l //
r = modulo ( a ,10) ;
b (1 , q ) = r ;
a = a /10;
a = floor ( a ) ;
q = q +1;
end
for m =1: q -1
c = m -1
f = f + b (1 , m ) *(2^ c ) ;
end
hex = dec2hex ( f ) ;
printf ( D i f f e r e n c e i n d e c i m a l n o t a t i o n i s %d\n\n
,f ) ;
printf ( D i f f e r e n c e i n h e x a d e c i m a l n o t a t i o n i s %s
\n , hex ) ;

Scilab code Exa 6.5.a.i 8 bit adder

65

1 // exmple 6 . 5 ( a ) ( i )
2 clc ;
3 clear ;
4 // a=i n p u t ( e n t e r
5 // b=i n p u t ( e n t e r

t h e f i r s t 8 b i t number :
t h e s e c o n d 8 b i t number :

;
6
7
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

a =01100001 ;
// t a k i n g g i v e n i n p u t s //
b =00011101 ;
for i =1:8
a1 ( i ) = modulo ( a ,10) ;
a = a /10;
a = round ( a ) ;
b1 ( i ) = modulo ( b ,10) ;
b = b /10;
b = round ( b ) ;
end
car (1) =0;
for i =1:8
// a d d i n g b o t h t h e i n p u t s ( b i n a r y a d d i t i o n ) //
c1 ( i ) = car ( i ) + a1 ( i ) + b1 ( i ) ;
if c1 ( i ) == 2 then
car ( i +1) = 1;
c1 ( i ) =0;
elseif c1 ( i ) ==3 then
car ( i +1) = 1;
c1 ( i ) =1;
else
car ( i +1) =0;
end
end
c1 (9) = car (9) ;
re =0;
format ( v ,18) ;
for i =1:9
re = re +( c1 ( i ) *(10^( i -1) ) )
end
66

) ;
)

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

printf ( The sum o f g i v e n two b i n a r y numbers i s %d


\n , re ) ;
q =1;
b =0;
f =0;
a = re ;
while ( a >0)
// c o n v e r t i n g t h e r e s u l t t o a h e x a d e c i m a l no //
r = modulo ( a ,10) ;
b (1 , q ) = r ;
a = a /10;
a = floor ( a ) ;
q = q +1;
end
for m =1: q -1
c = m -1;
f = f + b (1 , m ) *(2^ c ) ;
end
hex = dec2hex ( f ) ;
printf ( The sum i n h e x a d e c i m a l n o t a t i o n i s %s \n ,
hex ) ;
disp ( t h e sum i n d e c i m a l form i s : )
disp ( f )
// d i s p l a y i n g r e s u l t //

Scilab code Exa 6.5.a.ii 8 bit subtractor


1
2
3
4
5
6

// exmple 6 . 5 . a ( i i )
clc ;
clear ;
a =0;
b =0;
q =0;
67

7
8

// bb=i n p u t (
E n t e r t h e f i r s t no ( i n d e c i m a l )
:
) ;
// aa=i n p u t (
E n t e r t h e number from
which f i r s t no h a s t o s u b s t r a c t e d :
) ;
aa =97;
// t a k i n g t h e g i v e n i n p u t //
bb =29;

9
10
11
12
13 while ( aa >0)
14 // c o n v e r t i n g t h e i n p u t s i n t o b i n a r y numbers //
15
x = modulo ( aa ,2) ;
16
a = a + (10^ q ) * x ;
17
aa = aa /2;
18
aa = floor ( aa ) ;
19
q = q +1;
20 end
21 q =0;
22 while ( bb >0)
23
x = modulo ( bb ,2) ;
24
b = b + (10^ q ) * x ;
25
bb = bb /2;
26
bb = floor ( bb ) ;
27
q = q +1;
28 end
29 printf ( \ nThe b i n a r y e q u i v a l e n t o f f i r s t no i s %f\
30
31
32
33
34
35
36
37
38
39
40

n \n ,b ) ;
printf ( The b i n a r y e q u i v a l e n t o f s e c o n d no i s %f\n
\n ,a ) ;
for i =1:40
a1 ( i ) = modulo ( a ,10) ;
a = a /10;
a = round ( a ) ;
b1 ( i ) = modulo ( b ,10) ;
b = b /10;
b = round ( b ) ;
end
bro (1) =0;
for i =1:40
68

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

c1 ( i ) = a1 ( i ) - b1 ( i ) - bro ( i ) ;
// f i n d i n g t h e d i f f e r e n c e o f t h e g i v e n i n p u t s //
if c1 ( i ) == -1 then
bro ( i +1) = 1;
c1 ( i ) =1;
elseif c1 ( i ) == -2 then
bro ( i +1) = 1;
c1 ( i ) =0;
else
bro ( i +1) =0;
end
end
re =0;
format ( v ,18) ;
for i =1:40
re = re +( c1 ( i ) *(10^( i -1) ) )
end
printf ( The d i f e r e n c e o f g i v e n two numbers i s %f\
n\n , re ) ;
q =1;
b =0;
f =0;
a = re ;
while ( a >0)
r = modulo ( a ,10) ;
b (1 , q ) = r ;
a = a /10;
a = floor ( a ) ;
q = q +1;
end
for m =1: q -1
c = m -1
f = f + b (1 , m ) *(2^ c ) ;
end
hex = dec2hex ( f ) ;
printf ( D i f f e r e n c e i n d e c i m a l n o t a t i o n i s %d\n\n
,f ) ;
69

77
78

// d i s p l a y i n g t h e r e s u l t s //
printf ( D i f f e r e n c e i n h e x a d e c i m a l n o t a t i o n i s %s
\n , hex ) ;

Scilab code Exa 6.5.b.i 8 bit adder


1 // exmple 6 . 5 ( b ) ( i )
2 clc ;
3 clear ;
4 // a=i n p u t ( e n t e r
5 // b=i n p u t ( e n t e r

t h e f i r s t 8 b i t number :
t h e s e c o n d 8 b i t number :

;
6
a =00011000 ;
7 // t a k i n g g i v e n i n p u t s //
8
b =00111010 ;
9
for i =1:8
10
a1 ( i ) = modulo ( a ,10) ;
11
a = a /10;
12
a = round ( a ) ;
13
b1 ( i ) = modulo ( b ,10) ;
14
b = b /10;
15
b = round ( b ) ;
16
end
17
car (1) =0;
18
for i =1:8
19 // a d d i n g b o t h t h e i n p u t s ( b i n a r y a d d i t i o n ) //
20 c1 ( i ) = car ( i ) + a1 ( i ) + b1 ( i ) ;
21 if c1 ( i ) == 2 then
22 car ( i +1) = 1;
23
24
c1 ( i ) =0;
25 elseif c1 ( i ) ==3 then
26
car ( i +1) = 1;

70

) ;
)

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

c1 ( i ) =1;
else
car ( i +1) =0;
end
end
c1 (9) = car (9) ;
re =0;
format ( v ,18) ;
for i =1:9
re = re +( c1 ( i ) *(10^( i -1) ) )
end
printf ( The sum o f g i v e n two b i n a r y numbers i s %d
\n , re ) ;
q =1;
b =0;
f =0;
a = re ;
while ( a >0)
// c o n v e r t i n g t h e r e s u l t t o a h e x a d e c i m a l no //
r = modulo ( a ,10) ;
b (1 , q ) = r ;
a = a /10;
a = floor ( a ) ;
q = q +1;
end
for m =1: q -1
c = m -1;
f = f + b (1 , m ) *(2^ c ) ;
end
hex = dec2hex ( f ) ;
printf ( The sum i n h e x a d e c i m a l n o t a t i o n i s %s \n ,
hex ) ;
disp ( t h e sum i n d e c i m a l form i s : )
disp ( f )
// d i s p l a y i n g r e s u l t //

71

Scilab code Exa 6.5.b.ii 8 bit subtractor


1
2
3
4
5
6
7
8

// exmple 6 . 5 . b ( i i )
clc ;
clear ;
a =0;
b =0;
q =0;
// bb=i n p u t (
E n t e r t h e f i r s t no ( i n d e c i m a l )
:
) ;
// aa=i n p u t (
E n t e r t h e number from
which f i r s t no h a s t o s u b s t r a c t e d :
) ;
aa =58;
// t a k i n g t h e g i v e n i n p u t //
bb =24;

9
10
11
12
13 while ( aa >0)
14 // c o n v e r t i n g t h e i n p u t s i n t o b i n a r y numbers //
15
x = modulo ( aa ,2) ;
16
a = a + (10^ q ) * x ;
17
aa = aa /2;
18
aa = floor ( aa ) ;
19
q = q +1;
20 end
21 q =0;
22 while ( bb >0)
23
x = modulo ( bb ,2) ;
24
b = b + (10^ q ) * x ;
25
bb = bb /2;
26
bb = floor ( bb ) ;
27
q = q +1;
28 end

72

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
61
62
63

printf ( \ nThe b i n a r y e q u i v a l e n t o f f i r s t no i s %f\


n \n ,b ) ;
printf ( The b i n a r y e q u i v a l e n t o f s e c o n d no i s %f\n
\n ,a ) ;
for i =1:40
a1 ( i ) = modulo ( a ,10) ;
a = a /10;
a = round ( a ) ;
b1 ( i ) = modulo ( b ,10) ;
b = b /10;
b = round ( b ) ;
end
bro (1) =0;
for i =1:40
c1 ( i ) = a1 ( i ) - b1 ( i ) - bro ( i ) ;
// f i n d i n g t h e d i f f e r e n c e o f t h e g i v e n i n p u t s //
if c1 ( i ) == -1 then
bro ( i +1) = 1;
c1 ( i ) =1;
elseif c1 ( i ) == -2 then
bro ( i +1) = 1;
c1 ( i ) =0;
else
bro ( i +1) =0;
end
end
re =0;
format ( v ,18) ;
for i =1:40
re = re +( c1 ( i ) *(10^( i -1) ) )
end
printf ( The d i f e r e n c e o f g i v e n two numbers i s %f\
n\n , re ) ;
q =1;
b =0;
f =0;
a = re ;
73

64
65
66
67
68
69
70
71
72
73
74
75
76

while ( a >0)
r = modulo ( a ,10) ;
b (1 , q ) = r ;
a = a /10;
a = floor ( a ) ;
q = q +1;
end
for m =1: q -1
c = m -1
f = f + b (1 , m ) *(2^ c ) ;
end
hex = dec2hex ( f ) ;
printf ( D i f f e r e n c e i n d e c i m a l n o t a t i o n i s %d\n\n
,f ) ;
77 // d i s p l a y i n g t h e r e s u l t s //
78 printf ( D i f f e r e n c e i n h e x a d e c i m a l n o t a t i o n i s %s
\n , hex ) ;

74

Chapter 7
Flip flops

Scilab code Exa 7.1 clocked SR flip flop


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

// e x a m p l e 7 . 1 / /
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s t h e command window //
e = input ( E n t e r t h e e n a b l e i / p l e v e l ( 1 o r 0 ) : ) ;
// a c c e p t i n g t h e i n p u t o f e n a b l e //
r = input ( e n t e r t h e R i / p l e v e l ( 1 o r 0 ) : ) ;
// a c c e p t i n g t h e i n p u t s from t h e u s e r //
s = input ( e n t e r t h e S i /p l e v e l ( 1 o r 0 ) : ) ;
// a c c e p t i n g t h e i n p u t S from t h e u s e r //
qn = input ( E n t e r t h e p r e v i o u s o u t p u t v a l u e ( 1 o r 0 ) : ) ;
// a c c e p t i n g t h e o l d i n p u t from t h e u s e r //
flag =0;
if e ==0 then
// c a l c u l a t i n g t h e o u t p u t //
op = qn ;
elseif ( s ==0 & r ==0) then
op = qn ;
75

20
21
22
23
24
25
26
27
28
29
30
31

elseif ( s ==1& r ==1) then


disp ( The i n p u t s a r e i l l e g a l )
flag =1;
else
op = s ;
end
if ( flag ==0)
disp ( o u t p u t (Qn+1)= )
disp ( op )
end
// d i s p l a y i n g t h e o u t p u t //

Scilab code Exa 7.2 convert SR flip flop to JK flip flop


1 // e x a m p l e 7 . 2 / /
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s t h e command window //
6 disp ( f o r SR f l i p f l o p Q( n+1)=S+R Q( n ) )
7 disp ( t h u s w i t h S=JQ & R = KQ we g e t c i r c u i t

b e h a v e s l i k e JK f l i p

flop )

76

which

Chapter 8
Sequential Logic Design

Scilab code Exa 8.2 maximum frequency


1
2
3
4
5
6
7
8
9
10
11
12
13
14

// e x a m p l e 8 . 2 / /
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s t h e command window //
s =4;
// s=s t a g e o f r i p p l e c o u n t e r //
d =50;
// d e l a y o f f l i p f l o p i n nano s e c //
p =30;
// p u l s e w i d t h i n nano s e c s //
f =1000/( s * d + p ) ;
disp ( maximum f r e q u e n c y ( i n MHz) i s )
disp ( f )

77

Chapter 9
Timing Circuits

Scilab code Exa 9.3 Schmitt trigger


1 // e x a m p l e 9 . 3 ( a ) //
2 clc
3 clear
4 V =0.1*13/100.1;
5 X =0.1*( -13) /100.1;
6 disp ( V(UT)= )
7 disp ( V )
8 disp ( V(LT)= )
9 disp ( X )

78

Chapter 10
A to D and D to A Converters

Scilab code Exa 10.1 find analog output of 4 bit D to A converter


1 // e x a m p l e 1 0 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( d i g i t a l i n p u t t o a n a l o g o u t p u t o f 4 b i t
7
8
9
10
11
12
13

follows )
for ( i =0:15)
x = dec2bin ( i ) ;
disp ( x )
disp ( i ) ;
i = i +1;
end
// d i s p l a y s t h e r e s u l t //

79

i s as

Scilab code Exa 10.2.a 4 bit unipolar D to A converter


1 // e x a m p l e 1 0 . 2 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( d i g i t a l i n p u t t o a n a l o g o u t p u t o f 4 b i t
7
8
9
10
11
12
13
14
15
16

i s as

follows )
for ( i =0:15)
x = dec2bin ( i ) ;
// 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 //
disp ( x )
// b i n a r y form o f t h e number //
disp ( i ) ;
// d e c i m a l form o f t h e number //
i = i +1;
end
// d i s p l a y s t h e r e s u l t //

Scilab code Exa 10.2.b 4 bit unipolar D to A converter after adjusting


the offset voltage
1 // e x a m p l e 1 0 . 2 ( b ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( d i g i t a l i n p u t t o a n a l o g o u t p u t o f 4 b i t

follows )
7 for ( i =0:15)
8 x = dec2bin ( i ) ;
9 // 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 //
80

i s as

10 disp ( x )
11 // b i n a r y number //
12 j =i -8;
13 disp ( j ) ;
14 // a n a l o g number //
15 i = i +1;
16 end
17 // d i s p l a y s t h e r e s u l t //

Scilab code Exa 10.2.c 4 bit unipolar D to A converter after complimenting MSB
1 // e x a m p l e 1 0 . 2 ( c ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( d i g i t a l i n p u t t o a n a l o g o u t p u t o f 4 b i t a s p e r
7
8
9
10
11
12
13
14
15
16
17
18
19
20

given c o n d i t i o n i s as f o l l o w s )
for ( i =0:7)
x = dec2bin ( i ) ;
// 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 ( x )
// d i s p l a y s b i n a r y o r s a y d i g i t a l form //
disp ( i )
// d i s p l a y s a n a l o g form //
i = i +1;
end
for ( i =8:15)
x = dec2bin ( i ) ;
// c o n v e r s i o n //
disp ( x )
f =i -8;
81

21
22
23
24
25
26
27

y =2* f ;
t =y - i ;
disp ( t )
// d i s p l a y s a n a l o g form //
i = i +1
end
// d i s p l a y s t h e r e s u l t //

Scilab code Exa 10.3 D to A converter in ones complement form


1 // e x a m p l e 1 0 . 3 / /
2 clc
3 // c l e a r s t h e window //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( s i n c e t h e 1 s c o m p l i m e n t r e p r e s e n t a t i o n s

of

t h e p o s i t i v e numbers +0 t o +7 a r e same a s t h e
r e p r e s e n t a t i o n s o f t h e u n i p o l a r b i n a r y numbers ,
no o f f s e t v o l t a g e i s r e q u i r e d f o r t h e s e i n p u t s . )
7 disp ( For t h e n e g a t i v e numbers 1 1 1 1 t o 1 0 0 0 , t h e
o u t p u t a n a l o g v o l t a g e i s t o be o f f s e t by 15V .
T h i s can be a c h i e v e d by o p e r a t i n g a s w i t c h w i t h
MSB o f i n p u t t o i n t r o d u c e p r o p e r v a l u e o f V o f f . )
8 // a n s w e r //

Scilab code Exa 10.4 2 decade BCD D to A converter


1
2

// e x a m p l e 1 0 . 4 / /
// d e s i g n a 2 d e c a d e BCD D/A c o n v e r t e r //
82

3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
7 disp ( t h e c i r c u i t o f g i v e n f i g u r e can be u s e d f o r

BCD D/A c o n v e r t e r . The b i n a r y i n p u t s


c o r r e s p o n d i n g t o LSB a r e a p p l i e d t o b3 , b2 , b1 , b0
and t h o s e c o r r e s p o n d i n g t o t h e n e x t d i g i t a t b7 ,
b6 , b5 , b4 . t h e v a l u e o f r i s c h o s e n s o a s t o make
t h e i n p u t c u r r e n t o f OPAMP c o r r e s p o n d i n g t o LSD
a s 1 / 1 0 t h o f t h a t o f c u r r e n t due t o MSD, and i s
g i v e n by )
8 disp ( ( (V(R) ( 8 / 7 R) ) / (R ( r +8R/ 7 )+r 8 / 7 R) )=V(R)
/ ( 1 0 R) )
9 disp ( r =4.8R )

Scilab code Exa 10.5 determine the quantization interval


1 // e x a m p l e 1 0 . 5 / /
2 clc
3 // c l e a r s t h e window //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( t h e d i g i t a l v a l u e 000 s h o u l d be a s s i g n e d t o

t h e a n a l o g v o l t a g e i n t e r v a l 0V +S / 2 , S i n c e i n 2
s c o m p l i m e n t r e p r e s e n t a t i o n , t h e r e i s one more
n e g a t i v e number t h a n t h e number o f p o s i t i v e
numbers , t h e a n a l o g v o l t a g e from V t o +V s h o u l d
be d i v i d e d i n s e v e n i n t e r v a l s , e a c h o f s i z e S=2V
/ 7 , and one d i g i t a l v a l u e i s t o be a s s i g n e d t o
e a c h i n t e r v a l . The e x t r a d i g i t o u t p u t 100 can be
u s e d t o r e p r e s e n t t h e i n t e r v a l V t o 9V/7 )

83

Chapter 11
Semiconductor Memories

Scilab code Exa 11.1 Binary address of each location of size 16 words
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// e x a m p l e 1 1 . 1 / /
clc
// c l e a r s t h e s c r e e n //
clear
// c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
for ( i =0:15)
disp ( word number t o b i n a r y a d d r e s s i s a s f o l l o w s : )
disp ( i )
// d i s p l a y s t h e word number //
t = dec2bin ( i ) ;
// c o n v e r t s i t i n t o memory a d d r e s s //
disp ( t )
// d i s p l a y s b i n a r y a d d r e s s //
i = i +1
end

84

Scilab code Exa 11.2.a maximum rate at which data can be stored
1 // e x a m p l e 1 1 . 2 ( a ) //
2 //maximum r a t e a t which d a t a can be s t o r e d //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
7 disp ( t h e maximum r a t e a t which d a t a can be s t o r e d

is : )
8 t =200*(10^ -9) ;
9 // w r i t e c y c l e t i m e //
10 r =1/ t ;
11 //maximum r a t e //
12 disp ( r )
13 disp ( words / s e c )

Scilab code Exa 11.2.b maximum rate at which data can be read
1 // e x a m p l e 1 1 . 2 ( b ) //
2 //maximum r a t e a t which d a t a can be r e a d //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
7 disp ( t h e maximum r a t e a t which d a t a can be r e a d

)
8 t =200*(10^ -9) ;

85

is :

9 // r e a d c y c l e t i m e //
10 r =1/ t ;
11 //maximum r a t e //
12 disp ( r )
13 disp ( words / s e c )

Scilab code Exa 11.6.a data output


1 // e x a m p l e 1 1 . 6 ( a ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( s i n c e Y( 5 ) =0 , t h e memory l o c a t i o n 5 i s
7
8
9

s e l e c t e d f o r r e a d out , i . e . )
disp ( D1D0=01 )
disp ( t h e memory c o n t e n t s do n o t c h a n g e )
// g i v e n A1A0=00 , W = 1 , Y=11011111//

Scilab code Exa 11.6.b data output


1 // e x a m p l e 1 1 . 6 ( b ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( s i n c e Y5=Y4=0 , t h e memory l o c a t i o n s 4 and 5

a r e s e l e c t e d f o r r e a d o u t . The o u t p u t i s o b t a i n e d
by ORing t h e c o n t e n t s o f t h e s e l o c a t i o n s , i . e . )
86

7
8
9

disp ( D1D0=11 )
disp ( The memory c o n t e n t s do n o t c h a n g e )
// g i v e n A1A0=00 , W = 1 , Y=11001111//

Scilab code Exa 11.6.c data output


1 // e x a m p l e 1 1 . 6 ( c ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( s i n c e Y( 3 ) , w r i t e o p e r a t i o n i s p e r f o r m e d a t

memory l o c a t i o n 3 . The i n p u t d a t a i s s t o r e d i n
t h i s l o c a t i o n and a l s o a p p e a r s a t t h e o u t p u t )
7 disp ( D1D0=00 )
8 disp ( c o n t e n t s o f memory l o c a t i o n 3=00 )
9 // g i v e n A1A0=00 , W = 0 , Y=11110111//

Scilab code Exa 11.6.d data output


1 // e x a m p l e 1 1 . 6 ( d ) //
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 disp ( I n t h i s c a s e , t h e memory l o c a t i o n s 3 and 5 a r e

s e l e c t e d f o r w r i t i n g s i n c e Y3=Y5=0. The c o n t e n t s
o f t h e s e l o c a t i o n s w i l l become 10 and )
7 disp ( D1D0=10 )
87

8
9

// g i v e n A1A0=00 , W = 0 , Y=11010111//
// I 1 I 0 =10//

Scilab code Exa 11.7.a output and change in memory location


1 // e x a m p l e 1 1 . 7 / /
2 clc
3 // c l e a r s t h e s c r e e n //
4 clear
5 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
6 // g i v e n A1A0=11 , I 1 I 0 =01//
7 disp ( t h e a s s o c i a t i o n o p e r a t i o n i s p e r f o r m e d w i t h

keyword 0 1 . The memory l o c a t i o n s 1 , 5 and 7 match


t h e keyword g i v i n g o u t l o g i c 0 a t t h e
corresponding Y outputs . Therefore , )
8 disp ( Y=01011101 )

88

Chapter 12
Programmable Logic Design

Scilab code Exa 12.1 find the product term


1 // e x a m p l e 1 2 . 1 / /
2 // f i n d t h e p r o d u c t term //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
7 disp ( For an open l i n k , t h e i n p u t t o AND g a t e

l o g i c 1 , whereas f o r a
corresponding input to
the voltage applied at
8 disp ( P( o )=I ( o ) I ( 2 ) I ( 3 )

is

c l o s e d l i n k the
t h e AND g a t e i s same a s
that input , t h e r e f o r e , )
I (6) )

89

Chapter 14
Computer Aided Design of
Digital Systems

Scilab code Exa 14.2 entity construction for EXOR circuit


1 // e x a m p l e 1 4 . 2 / /
2 // e n t i t y c o n s t r u c t i o n f o r EXOR c i r c u i t //
3 clc
4 // c l e a r s t h e s c r e e n //
5 clear
6 // c l e a r s a l r e a d y e x i s t i n g v a r i a b l e s //
7 disp ( L e t t h e name o f e n t i t y be C i r c u i t F i g .

8
9
10
11

I t has
two i n p u t p o r t s A and B and one o u t p u t p o r t Y .
The e n t i t y d e c l a r a t i o n f o r t h i s c i r c u i t w i l l be )
disp ( ENTITY C i r c u i t F i g I S )
disp ( PORT(A, B : IN BIT ; OUT BIT ) ; )
disp ( END C i r c u i t F i g ; )
disp ( From t h i s e n t i t y d e c l a r a t i o n , we o b s e r v e t h a t
a l t h o u g h t h i s c i r c u i t c o n s i s t s o f AND, OR and NOT
g a t e s , t h e c i r c u i t i t s e l f i s an e n t i t y and t h e
e n t i t y d e c l a r a t i o n g i v e s no i n f o r m a t i o n a b o u t t h e
s t r u c t u r e or behaviour of the c i r c u i t )
90

91

You might also like