Digital Electronics- An Introduction To Theory And Practice_w. H. Gothmann

  • Uploaded by: Siêu Nhân Bụng Mỡ
  • 0
  • 0
  • January 2021
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Digital Electronics- An Introduction To Theory And Practice_w. H. Gothmann as PDF for free.

More details

  • Words: 38,998
  • Pages: 104
Loading documents preview...
Scilab Textbook Companion for Digital Electronics: An Introduction To Theory And Practice by W. H. Gothmann1 Created by Aritra Ray B.Tech Electronics Engineering NIT-DURGAPUR College Teacher Prof. Sabyasachi Sengupta,iit-kharagpur Cross-Checked by Lavitha M. Pereira November 11, 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: 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

1

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.

2

Contents List of Scilab Codes

4

2 Number Systems

7

3 Binary Codes

42

4 Boolean Algebra

58

6 Combinational Logic

62

11 Analog Digital Conversion

97

3

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

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

Convert 10111 to decimal . . . . . . . . Convert 1011101001 to decimal . . . . . Convert 110111 to decimal . . . . . . . Convert 43 to binary . . . . . . . . . . . Convert 200 to binary . . . . . . . . . . Convert 43 to binary . . . . . . . . . . . Convert 200 to binary . . . . . . . . . . Add 1011 and 110 . . . . . . . . . . . . Add 11110 and 11 . . . . . . . . . . . . Subtract one from 100 . . . . . . . . . . Multiply 1011 by 101 . . . . . . . . . . Multiply 11010 by 11011 . . . . . . . . . Divide 110110 by 101 . . . . . . . . . . Convert 1010111010 to hexadecimal . . Convert 11011110101110 to hexadecimal Convert 4A8C to binary . . . . . . . . . Convert FACE to binary . . . . . . . . . Convert 2C9 to decimal . . . . . . . . . Convert EB4A to decimal . . . . . . . . Convert 423 to hexadecimal . . . . . . . Convert 72905 to hexadecimal . . . . . Add 1A8 and 67B . . . . . . . . . . . . Add ACEF1 and 16B7D . . . . . . . . . Subtract 3A8 from 1273 . . . . . . . . . Multiply 1A3 by 89 . . . . . . . . . . . Divide 1EC87 by A5 . . . . . . . . . . . Convert 11111011110101 to octal . . . . Convert 1011110100011000111 to octal . 4

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

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

Convert octal number 3674 to binary . . . . . . . . Minus 5 in twos complement form . . . . . . . . . 12 bit twos complement . . . . . . . . . . . . . . . 16 bit twos complement . . . . . . . . . . . . . . . Twos complement of minus4 second method . . . . Twos complement of minus17 second method . . . Twos complement of minus4 third method . . . . . Twos complement of minus17 third method . . . . Negative decimal number represented by 10011011 Add minus 17 to minus 30 . . . . . . . . . . . . . . Add minus 20 to 26 . . . . . . . . . . . . . . . . . Add minus 29 to 14 . . . . . . . . . . . . . . . . . Ones complement of minus 13 . . . . . . . . . . . . Ones complement of minus 13 second method . . . Ones complement addition using 4 bits . . . . . . . Ones complement addition using 4 bits . . . . . . . Ones complement addition using 8 bits . . . . . . . Convert 1101 point 000101 to decimal . . . . . . . Convert point 375 to binary . . . . . . . . . . . . . Convert point 54545 to binary . . . . . . . . . . . Convert 38 point 21 to binary . . . . . . . . . . . . Binary addition . . . . . . . . . . . . . . . . . . . . Binary mutiplication . . . . . . . . . . . . . . . . . Add 647 to 492 in BCD . . . . . . . . . . . . . . . Add 4318 and 7678 in BCD . . . . . . . . . . . . . Add 3 and 2 in XS3 . . . . . . . . . . . . . . . . . Add 6 and 8 in XS3 . . . . . . . . . . . . . . . . . Convert binary 1011 to Gray code . . . . . . . . . Convert binary 1001011 to Gray code . . . . . . . Convert Gray code 1011 to binary . . . . . . . . . Convert Gray code 1001011 to binary . . . . . . . Hamming code for 1011 . . . . . . . . . . . . . . . Hamming code for 0101 . . . . . . . . . . . . . . . Correction of Hamming code 1111101 . . . . . . . Demorganize a function . . . . . . . . . . . . . . . Reduce an expression . . . . . . . . . . . . . . . . Reduce an expression . . . . . . . . . . . . . . . . Reduce a boolean expression . . . . . . . . . . . . 5

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

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

Reduce a Boolean expression . . . . . . . . . . . . . Convert A plus B to minterms . . . . . . . . . . . . Find minterms for A plus BC . . . . . . . . . . . . . Find minterms for AB plus ACD . . . . . . . . . . . Minterm designation . . . . . . . . . . . . . . . . . . Minterm designation . . . . . . . . . . . . . . . . . . 2 variable mapping . . . . . . . . . . . . . . . . . . . 3 variable mapping . . . . . . . . . . . . . . . . . . . Mapping an expression . . . . . . . . . . . . . . . . Mapping an expression . . . . . . . . . . . . . . . . 4 variable mapping . . . . . . . . . . . . . . . . . . . Reduce an expression by Kmap . . . . . . . . . . . . Reduce an expression using Kmap . . . . . . . . . . Reduce expression by kmap . . . . . . . . . . . . . . Inputs Required . . . . . . . . . . . . . . . . . . . . Inputs required . . . . . . . . . . . . . . . . . . . . . Inputs required . . . . . . . . . . . . . . . . . . . . . Inputs required . . . . . . . . . . . . . . . . . . . . . Minimise expression using mapping . . . . . . . . . . Reduce using mapping . . . . . . . . . . . . . . . . . Kmap POS SOP . . . . . . . . . . . . . . . . . . . . Minimise expression . . . . . . . . . . . . . . . . . . Reduce kmap by POS . . . . . . . . . . . . . . . . . Find minimum of expression . . . . . . . . . . . . . Multiple output equation using mapping . . . . . . . Multiple output equation using mapping . . . . . . . Reduce by variable mapping . . . . . . . . . . . . . Reduce by variable mapping . . . . . . . . . . . . . Solve using 3 variable mapping . . . . . . . . . . . . Reduce by mapping . . . . . . . . . . . . . . . . . . Reducing expression by Kmap . . . . . . . . . . . . Percentage resolution of 5bit DA converter . . . . . . 6 bit analog to digital converter . . . . . . . . . . . . Compute the gain of an Opamp . . . . . . . . . . . . Compute the output voltage . . . . . . . . . . . . . Compute output voltage . . . . . . . . . . . . . . . . Resolution and Percent resolution 12bit DAconverter Resolution and Percent resolution 10bit ADconverter 6

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

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

Scilab code Exa 2.1 Convert 10111 to decimal 1 // Example 2 −1// 2 // 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 // 3 a = bin2dec ( ’ 1 0 1 1 1 ’ ) 4 // 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 // 5 disp ( a ) 6 // a n s w e r i n d e c i m a l form //

Scilab code Exa 2.2 Convert 1011101001 to decimal 1 // Example 2 −2// 2 // 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 // 3 a = bin2dec ( ’ 1 0 1 1 1 0 1 0 0 1 ’ ) 4 // 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 // 5 disp ( a ) 6 // a n s w e r i n d e c i m a l form //

7

Scilab code Exa 2.3 Convert 110111 to decimal 1 // Example 2 −3// 2 // 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 // 3 a = bin2dec ( ’ 1 1 0 1 1 1 ’ ) 4 // 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 // 5 disp ( a ) 6 // a n s w e r i n d e c i m a l form //

Scilab code Exa 2.4 Convert 43 to binary 1 // Example 2 −4// 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 //

Scilab code Exa 2.5 Convert 200 to binary 1 // Example 2 −5// 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 (200) 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 //

Scilab code Exa 2.6 Convert 43 to binary 1

// 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 //

Scilab code Exa 2.7 Convert 200 to binary 1 // Example 2 −7// 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 (200) 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 //

Scilab code Exa 2.8 Add 1011 and 110 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

// 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

’)

Scilab code Exa 2.9 Add 11110 and 11 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

// 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 //

Scilab code Exa 2.10 Subtract one from 100 1 2 3 4 5 6 7 8 9 10

// 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 //

Scilab code Exa 2.11 Multiply 1011 by 101 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

// 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 //

Scilab code Exa 2.12 Multiply 11010 by 11011 1 // Example 2 −12// 2 // B i n a r y m u l t i p l i c a t i o n // 3 clc 4 // c l e a r s t h e c o n s o l e // 5 clear

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 //

Scilab code Exa 2.13 Divide 110110 by 101 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

// 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 //

Scilab code Exa 2.14 Convert 1010111010 to hexadecimal 12

’)

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 //

Scilab code Exa 2.15 Convert 11011110101110 to hexadecimal 1 // Example 2 −15// 2 // b i n a r y t o h e x a d e c i m a l c o n v e r s i o n // 3 x = bin2dec ( ’ 1 1 0 1 1 1 1 0 1 0 1 1 1 0 ’ ) 4 // 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 // 5 a = dec2hex ( x ) 6 // Hex e q u i v a l e n t o f t h e d e c i m a l number // 7 disp ( a ) 8 // a n s w e r i n h e x a d e c i m a l form //

Scilab code Exa 2.16 Convert 4A8C to binary 1 // Example 2 −16// 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 x = hex2dec ( ’ 4A8C ’ ) 4 // 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 number // 5 a = dec2bin ( x ) 6 // 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 // 7 disp ( a ) 8 // a n s w e r i n b i n a r y form //

13

Scilab code Exa 2.17 Convert FACE to binary 1 // Example 2 −17// 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 x = hex2dec ( ’FACE ’ ) 4 // 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 number // 5 a = dec2bin ( x ) 6 // 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 // 7 disp ( a ) 8 // a n s w e r i n b i n a r y form //

Scilab code Exa 2.18 Convert 2C9 to decimal 1 // Example 2 −18// 2 // 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 // 3 a = hex2dec ( ’ 2C9 ’ ) 4 // d e c i m a l e q u i v a l e n t o f t h e h e x a d e c i m a l number // 5 disp ( a ) 6 // a n s w e r i n d e c i m a l form //

Scilab code Exa 2.19 Convert EB4A to decimal 1 // Example 2 −19// 2 // 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 // 3 a = hex2dec ( ’EB4A ’ ) 4 // d e c i m a l e q u i v a l e n t o f t h e h e x a d e c i m a l number // 5 disp ( a ) 6 // a n s w e r i n d e c i m a l form //

Scilab code Exa 2.20 Convert 423 to hexadecimal 14

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 //

Scilab code Exa 2.21 Convert 72905 to hexadecimal 1 // Example 2 −21// 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 (72905) 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 //

Scilab code Exa 2.22 Add 1A8 and 67B 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

// 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 //

Scilab code Exa 2.23 Add ACEF1 and 16B7D 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

// 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 //

Scilab code Exa 2.24 Subtract 3A8 from 1273 1 2 3 4 5 6 7 8 9 10

// 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 //

’)

Scilab code Exa 2.25 Multiply 1A3 by 89 // Example 6 −25// // 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 // 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 // x = hex2dec ( ’ 1A3 ’ ) y = hex2dec ( ’ 89 ’ ) // 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 // m u l t i p l i c a 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 ( ’ m u l t i p l i c a t i o n o f t h e 2 h e x a d e c i m a l numbers is ’) 15 disp ( a ) 16 // a n s w e r i n h e x a d e c i m a l form // 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Scilab code Exa 2.26 Divide 1EC87 by A5 1 // Example 2 −26// 2 // H e x a d e c i m a l D i v i s i o n // 3 x = hex2dec ( ’ 1EC87 ’ ) 4 y = hex2dec ( ’ A5 ’ )

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 //

Scilab code Exa 2.27 Convert 11111011110101 to octal 1 // Example 2 −27// 2 // B i n a r y t o o c t a l c o n v e r s i o n // 3 x = bin2dec ( ’ 1 1 1 1 1 0 1 1 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 t h e b i n a r y number // 5 a = dec2oct ( x ) 6 // o c t 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 // 7 disp ( a ) 8 // a n s w e r i n o c t a l form //

Scilab code Exa 2.28 Convert 1011110100011000111 to octal 1 // Example 2 −28// 2 // B i n a r y t o o c t a l c o n v e r s i o n // 3 x = bin2dec ( ’ 1 0 1 1 1 1 0 1 0 0 0 1 1 0 0 0 1 1 1 ’ ) 4 // 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 // 5 a = dec2oct ( x ) 6 // o c t 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 //

18

7 8

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

Scilab code Exa 2.29 Convert octal number 3674 to binary 1 // Example 2 −29// 2 // o c t a l t o b i n a r y c o n v e r s i o n // 3 x = oct2dec ( ’ 3 6 7 4 ’ ) 4 // d e c i m a l e q u i v a l e n t o f t h e o c t a l number // 5 a = dec2bin ( x ) 6 // 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 // 7 disp ( a ) 8 // a n s w e r i n b i n a r y form //

Scilab code Exa 2.30 Minus 5 in twos complement form 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

// 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

Scilab code Exa 2.31 12 bit twos complement 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

// 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 //

Scilab code Exa 2.32 16 bit twos complement 1

// Example 2 −32// 20

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

// −16000 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^16 // S m a l l e s t n i n e b i t number // y =16000 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 ( ’ −16000 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 //

Scilab code Exa 2.33 Twos complement of minus4 second method 1 // Example 2 −33// 2 // −4 i n t w o s complement form by s e c o n d method // 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 x = bitcmp (4 ,8) 8 // complement o f t h e d e c i m a l number 4 ( 8 b i t

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

Scilab code Exa 2.34 Twos complement of minus17 second method 1 // Example 2 −34// 2 // −17 i n t w o s complement form by s e c o n d method // 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 x = bitcmp (17 ,8) 8 // complement o f t h e d e c i m a l number 1 7 ( 8 b i t

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 //

Scilab code Exa 2.35 Twos complement of minus4 third method 1 2 3 4 5 6 7 8 9

// 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 //

Scilab code Exa 2.36 Twos complement of minus17 third method 1 2 3 4 5 6 7 8 9 10

// 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 //

Scilab code Exa 2.37 Negative decimal number represented by 10011011 1 // Example 2 −37// 2 // n e g a t i v e d e c i m a l r e p r e s e n t a t i o n o f 1 0 0 1 1 0 1 1 / / 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 b = bin2dec ( ’ 1 0 0 1 1 0 1 1 ’ ) 8 x = bitcmp (b ,8) 9 // complement o f t h e d e c i m a l number 1 7 ( 8 b i t

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 //

Scilab code Exa 2.38 Add minus 17 to minus 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

// 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 //

Scilab code Exa 2.39 Add minus 20 to 26 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

// 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 //

Scilab code Exa 2.40 Add minus 29 to 14 1

// 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

Scilab code Exa 2.41 Ones complement of minus 13 1 // Example 2 −41// 2 // one ’ s complement form o f −13// 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 x = bitcmp (13 ,8) 8 // complement o f 1 3 / / 9 a = dec2bin ( x ) 10 // 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 // 11 disp ( ’ o n e s complement form o f −13 ’ ) 12 disp ( a ) 13 // r e s u l t i s d i s p l a y e d //

27

Scilab code Exa 2.42 Ones complement of minus 13 second method 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

// 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 //

Scilab code Exa 2.43 Ones complement addition using 4 bits 1 2 3 4 5 6 7 8 9 10 11

// 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

Scilab code Exa 2.44 Ones complement addition using 4 bits // Example 2 −44// // 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 =2 y = bitcmp (3 ,4) // complement o f t h e d e c i m a l number 2// z=x+y 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 ’ ) 14 disp ( a ) 15 // r e s u l t i s d i s p l a y e d // 1 2 3 4 5 6 7 8 9 10 11 12 13

Scilab code Exa 2.45 Ones complement addition using 8 bits 29

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 //

Scilab code Exa 2.46 Convert 1101 point 000101 to decimal 1 2 3 4 5 6 7 8 9 10

// 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 //

Scilab code Exa 2.47 Convert point 375 to binary 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

// 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 //

Scilab code Exa 2.48 Convert point 54545 to binary 1 2 3 4 5 6 7 8 9 10 11

// 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 //

Scilab code Exa 2.49 Convert 38 point 21 to binary 1 // Example 2 −49// 2 // 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 // 3 clc

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 //

Scilab code Exa 2.50 Binary addition 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

// 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

o f the i n t e g e r part with 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 // 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 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) 37

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 //

Scilab code Exa 2.51 Binary mutiplication 1 2 3 4 5 6 7

// 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

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 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 39

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

Scilab code Exa 3.1 Add 647 to 492 in BCD 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

// 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

Scilab code Exa 3.2 Add 4318 and 7678 in BCD 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

// 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

Scilab code Exa 3.3 Add 3 and 2 in XS3 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

// 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

33 if c (5) ==0 then 34 z = dec2bin ( bin2dec ( ea ) + bin2dec ( eb ) -3) 35 end 36 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 37 38 39 40

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 //

Scilab code Exa 3.4 Add 6 and 8 in XS3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

// 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 //

Scilab code Exa 3.5 Convert binary 1011 to Gray code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

// 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

if bitand ( x ( k +1) ,x ( k ) ) ==1 then y ( k ) = bitcmp (1 ,1) 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: 4 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 //

Scilab code Exa 3.6 Convert binary 1001011 to Gray code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

// 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 //

Scilab code Exa 3.7 Convert Gray code 1011 to binary 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

// 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 //

Scilab code Exa 3.8 Convert Gray code 1001011 to binary 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

// 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 //

Scilab code Exa 3.9 Hamming code for 1011 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

// 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

Scilab code Exa 3.10 Hamming code for 0101 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

// 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

Scilab code Exa 3.11 Correction of Hamming code 1111101 1 // Example 3 −11// 2 // C o r r e c t i o n o f r e c e i v e d Hamming c o d e // 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 z =1111101

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

Scilab code Exa 4.1 Demorganize a function 1 // Example 4 −1// 2 // d e m o r g a n i z e f u n c t 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 f u n c t i o n i s a s f o l l o w s // 8 disp ( ’ Given f u n c t i o n − (AB ’ ’+C) ’ ’ ’ ) 9 disp ( ’ now d e m o r g a n i z i n g t h e f u n c t i o n ’ ) 10 disp ( ’ complement f u n c t i o n ’ ) 11 disp ( ’ AB ’ ’+C ’ ) 12 disp ( ’ c h a n g i n g o p e r a t o r s ’ ) 13 disp ( ’ (A+B ’ ’ ) (C) ’ ) 14 disp ( ’ complement v a r i a b l e s ’ ) 15 disp ( ’ (A ’ ’+B) (C ’ ’ ) ’ ) 16 // f i n a l a n s w e r d i s p l a y e d a f t e r s i m p l i f i c a t i o n //

Scilab code Exa 4.2 Reduce an expression 58

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 //

Scilab code Exa 4.3 Reduce an expression 1 // Example 4 −3// 2 // R e d u c i n g a g i v e n 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 − ( (AB) ’ ’+A ’ ’+AB) ’ ’ 9 disp ( ’ a p p l y i n g DeMorgan Theorem ’ ) 10 disp ( ’ r e d u c e d e x p r e s s i o n ’ ) 11 disp ( ’ (A ’ ’+B ’ ’+A ’ ’+AB) ’ ’ ’ ) 12 disp ( ’ a s A+A=A ’ ) 13 disp ( ’ (A ’ ’+B ’ ’+AB) ’ ’ ’ ) 14 //By law 2 0 / / 15 disp ( ’ (A ’ ’+B ’ ’+A) ’ ’ ’ ) 16 disp ( ’ r e a r r a n g i n g ’ )

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 /

Scilab code Exa 4.4 Reduce a boolean expression 1 // Example 4 −4// 2 // R e d u c i n g a g i v e n e x p r e s s i o n // 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 // 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 − AB+(AC) ’ ’+AB ’ ’C(AB+C) 9 disp ( ’ M u l t i p l y i n g ’ ) 10 disp ( ’ AB+(AC) ’ ’+AABB ’ ’C+AB ’ ’CC ’ ) 11 // u s i n g l a w s 1 8 , 6 , 8 , 9 / / 12 disp ( ’ AB+(AC) ’ ’+AB ’ ’C ’ ) 13 disp ( ’ a p p l y i n g DeMorgan t h e o r e m ’ ) 14 disp ( ’ AB+A ’ ’+C ’ ’+AB ’ ’C ’ ) 15 disp ( ’ r e a r r a n g e ’ ) 16 disp ( ’ AB+C ’ ’+A ’ ’+AB ’ ’C ’ ) 17 // r e d u c e u s i n g law 2 0 / / 18 disp ( ’ AB+C ’ ’+A ’ ’+B ’ ’C ’ ) 19 disp ( ’ r e a r r a n g i n g a g a i n ’ ) 20 disp ( ’ A ’ ’+AB+C ’ ’+B ’ ’C ’ ) 21 // r e d u c e u s i n g law 2 0 / / 22 disp ( ’ A ’ ’+B+C ’ ’+B ’ ’ ’ ) 23 // u s i n g l a w s 11 and 1 3 / / 24 disp ( ’ 1 ’ ) 25 // 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

’)

Scilab code Exa 4.5 Reduce a Boolean expression 1 // Example 4 −5// 2 // Reduce a g i v e n e x p r e s s i o n // 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 // 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 − ( (AB ’ ’+ABC) ’ ’+A(B+AB ’ ’ ) ) ’ ’ 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

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

Scilab code Exa 6.1 Convert A plus B to minterms 1 // Example 6 −1// 2 // c o n v e r t A+B t o m i n t e r m s // 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+B ’) 9 disp ( ’ on s o l v i n g ’ ) 10 disp ( ’ A(B+B ’ ’ )+B(A+A ’ ’ ) ’ ) 11 disp ( ’ m u l t i p l y i n g ’ ) 12 disp ( ’ AB+AB ’ ’+AB+A ’ ’B ’) 13 disp ( ’ we know A+A=A ’ ) 14 disp ( ’ AB+AB ’ ’+A ’ ’B ’) 15 // f i n a l r e s u l t i s d i s p l a y e d //

Scilab code Exa 6.2 Find minterms for A plus BC

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 //

’)

Scilab code Exa 6.3 Find minterms for AB plus ACD 1 // Example 6 −3// 2 // f i n d m i n t e r m s f o r AB+ACD// 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 // 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 − AB+ACD ’ ) 9 disp ( ’ on s o l v i n g ’ ) 10 disp ( ’ AB(C+C ’ ’ ) (D+D ’ ’ )+ACD(B+B ’ ’ ) ’ ) 11 disp ( ’ m u l t i p l y i n g ’ ) 12 disp ( ’ ABCD+ABC ’ ’D ’ ’+ABC ’ ’D+ABCD ’ ’+AB ’ ’CD+ABCD 13 disp ( ’ we know A+A=A ’ ) 14 disp ( ’ ABC ’ ’D ’ ’+ABC ’ ’D+ABCD ’ ’+AB ’ ’CD+ABCD ’) 15 // r e s u l t i s d i s p l a y e d //

63

’)

Scilab code Exa 6.4 Minterm designation 1 // Example 6 −4// 2 // minterm d e s i g n a t i o n o f AB’ ’ C ’ ’ D’ ’ / / 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 ( ’ copy o r i g i n a l term ’ ) 8 disp ( ’ AB ’ ’C ’ ’D ’ ’ ’) 9 disp ( ’ s u b s t i t u t e o n e s f o r n o n b a r r e d l e t t e r s and

zeroes for barred l e t t e r s

’)

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 //

Scilab code Exa 6.5 Minterm designation 1 // Example 6 −5// 2 // minterm d e s i g n a t i o n o f W’ ’ X’ ’ YZ ’ ’ / / 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 ( ’ copy o r i g i n a l term ’ ) 8 disp ( ’ W’ ’X ’ ’YZ ’ ’ ’) 9 disp ( ’ s u b s t i t u t e o n e s f o r n o n b a r r e d l e t t e r s and

zeroes for barred l e t t e r s 10 disp ( ’ a f t e r s u b s t i t u t i o n ’ ) 11 disp ( ’ 0 0 1 0 ’ ) 64

’)

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 //

Scilab code Exa 6.6 2 variable mapping 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

// 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

27 n = strcat ([ b (2 ,1) ,b (2 ,2) ]) 28 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 ’ ) 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 //

Scilab code Exa 6.7 3 variable mapping 1 // Example 6 −7// 2 //Map X=ABC+AB’ ’ C+AB’ ’ C’ ’ / / 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 ( ’ B ’ ’C ’ ’ B ’ ’C BC BC ’ ’ ’ ) 9 disp ( ’A ’ ’ 0 0 0 0 ’) 10 disp ( ’A 1 1 1 0 ’) 11 disp ( ’ From t h e map , h i g h o u t p u t s f o r 4 , 5 and 7 ’ ) 12 a =[1 0 0 ; 1 0 1 ; 1 1 1] 13 disp ( a ) 14 for i =1: 3 15 if a (i ,1) ==1 then 16 b (i ,1) = ’A ’ 17 else 18 b (i ,1) = ’A ’ ’ ’ 19 end 20 if a (i ,2) ==1 then 21 b (i ,2) = ’B ’ 22 else 23 b (i ,2) = ’B ’ ’ ’ 24 end 25 if a (i ,3) ==1 then 26 b (i ,3) = ’C ’

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 //

Scilab code Exa 6.8 Mapping an expression 1 // Example 6 −8// 2 // Mapping an e q u a t 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 ( ’ Z=m( 9 , 2 0 , 2 1 , 2 9 , 3 0 , 3 1 ) ’ ) 9 disp ( ’ A’ ’ 10 11 12 13 14

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

disp ( ’ From t h e map , h i g h o u t p u t s f o r 9 ,20 ,21 ,29 ,30 ,31 ’) 16 // T h e r e f o r e t h e kmap i s d i s p l a y e d // 15

Scilab code Exa 6.9 Mapping an expression 1 // Example 6 −8// 2 // Mapping an e q u a t 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 ( ’ Z=m

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

0

1

1

0

0

0

0

1

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 ( ’

Scilab code Exa 6.10 4 variable mapping 1 // Example 6 −10// 2 //Map L=W’ ’ X’ ’ YZ+WX’ ’ YZ’ ’ +WX’ ’ Y’ ’ Z ’ ’ +W’ ’ XYZ// 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 ( ’ C ’ ’D ’ ’ C ’ ’D CD CD ’ ’ ’ ) 9 disp ( ’A ’ ’B ’ ’ 0 0 1 0 ’) 10 disp ( ’AB ’ ’ 0 0 1 0 ’) 11 disp ( ’AB 0 0 0 0 ’) 12 disp ( ’AB ’ ’ 1 0 0 1 ’) 13 disp ( ’ From t h e map , h i g h o u t p u t s f o r 3 , 7 , 8 , 1 0 14 a =[0 0 1 1 ; 0 1 1 1 ; 1 0 0 0 ; 1 0 1 0] 15 disp ( a ) 16 for i =1: 4 17 if a (i ,1) ==1 then 18 b (i ,1) = ’W’ 19 else 20 b (i ,1) = ’W’ ’ ’ 21 end 22 if a (i ,2) ==1 then 23 b (i ,2) = ’X ’ 24 else

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 //

Scilab code Exa 6.11 Reduce an expression by Kmap 1 // Example 6 −11// 2 // r e d u c e e x p r e s s i o n u s i n g k−map// 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 // Mapping t h e e x p r e s s i o n // 8 disp ( ’ C ’ ’D ’ ’ C ’ ’D CD CD ’ ’ ’ ) 9 disp ( ’A ’ ’B ’ ’ 1 1 1 1 ’) 10 disp ( ’AB ’ ’ 0 0 1 1 ’)

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

46 x7 = strcat ([ b (7 ,1) ,b (7 ,2) ,b (7 ,3) ,b (7 ,4) ]) 47 x8 = strcat ([ b (8 ,1) ,b (8 ,2) ,b (8 ,3) ,b (8 ,4) ]) 48 x =([ x1 ”+” , x2 ”+” , x3 ”+” , x4 ”+” , x5 ”+” , x6 ”+” , x7 ”+” , x8 ]) 49 disp ( x ) 50 // E x p r e s s i o n i s d i s p l a y e d // 51 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 ’ 52

) disp ( ’A ’ ’B ’ ’+A ’ ’C+ABD ’ )

Scilab code Exa 6.12 Reduce an expression using Kmap 1 // Example 6 −12// 2 // r e d u c e e x p r e s s i o n u s i n g k−map// 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 // Mapping t h e e x p r e s s i o n // 8 disp ( ’ C ’ ’D ’ ’ C ’ ’D CD CD ’ ’ ’ ) 9 disp ( ’A ’ ’B ’ ’ 0 0 1 1 ’) 10 disp ( ’AB ’ ’ 0 1 1 0 ’) 11 disp ( ’AB 1 1 1 1 ’) 12 disp ( ’AB ’ ’ 0 1 1 0 ’) 13 disp ( ’ From t h e map , h i g h o u t p u t s f o r 14 15 16 17 18 19 20 21 22

2 ,3 ,5 ,7 ,9 ,11 ,12 ,13 ,14 ,15 ’) // g i v e n l o g i c e q u a t i o n // a =[0 0 1 0;0 0 1 1;0 1 0 1;0 1 1 1 ;1 0 0 1;1 0 1 1;1 1 0 0;1 1 0 1;1 1 1 0;1 1 1 1] disp ( a ) for i =1: 10 if a (i ,1) ==1 then b (i ,1) = ’A ’ else b (i ,1) = ’A ’ ’ ’ end 72

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

Scilab code Exa 6.13 Reduce expression by kmap 1 // Example 6 −13// 2 // r e d u c e e x p r e s s i o n u s i n g k−map// 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 ( ’ B ’ ’C ’ ’ B ’ ’C BC BC ’ ’ ’ ) 9 disp ( ’A ’ ’ 1 0 1 1 ’) 10 disp ( ’A 1 1 1 0 ’) 11 disp ( ’ From t h e map , h i g h o u t p u t s f o r 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

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

Scilab code Exa 6.14.a Inputs Required 1 // e x a m p l e 6−14 a // 2 // Number o f i n p u t s r e q u i r e d // 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 ( ’ W=AB ’ ’D+ACD ’ ’+EF ’ ) 8 disp ( ’ c o u n t AND i n p u t s ’ ) 9 disp ( ’ 3+3+2=8 ’ ) 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 =11 ’ ) 13 // r e s u l t i s d i s p l a y e d //

Scilab code Exa 6.14.b Inputs required 1 2

// e x a m p l e 6−14b // // 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 //

Scilab code Exa 6.14.c Inputs required 1 // e x a m p l e 6−14 c // 2 // Number o f i n p u t s r e q u i r e d // 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 ( ’ Y=ST ’ ’U ’ ’V+STO ’ ’V+UV ’ ’+SUV+TU ’ ’V ’ ’ 8 disp ( ’ c o u n t AND i n p u t s ’ ) 9 disp ( ’ 4+4+2+3+3=16 ’ ) 10 disp ( ’ c o u n t OR i n p u t s ’ ) 11 disp ( ’ 1+1+1+1+1=5 ’ ) 12 disp ( ’ t h e r e f o r e t o t a l i n p u t s =21 ’ ) 13 // r e s u l t i s d i s p l a y e d //

Scilab code Exa 6.14.d Inputs required 1 // e x a m p l e 6−14d // 2 // Number o f i n p u t s 3 clc

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 //

Scilab code Exa 6.15 Minimise expression using mapping 1 // Example 6 −15// 2 // Mapping an e q u a t 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 ( ’ Z=m 9 10 11 12 13 14 15

(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

x3 = strcat ([ b (3 ,1) ,b (3 ,2) ,b (3 ,3) ,b (3 ,4) ,b (3 ,5) ]) x4 = strcat ([ b (4 ,1) ,b (4 ,2) ,b (4 ,3) ,b (4 ,4) ,b (4 ,5) ]) x5 = strcat ([ b (5 ,1) ,b (5 ,2) ,b (5 ,3) ,b (5 ,4) ,b (5 ,5) ]) x6 = strcat ([ b (6 ,1) ,b (6 ,2) ,b (6 ,3) ,b (6 ,4) ,b (6 ,5) ]) x7 = strcat ([ b (7 ,1) ,b (7 ,2) ,b (7 ,3) ,b (7 ,4) ,b (7 ,5) ]) x8 = strcat ([ b (8 ,1) ,b (8 ,2) ,b (8 ,3) ,b (8 ,4) ,b (8 ,5) ]) x9 = strcat ([ b (9 ,1) ,b (9 ,2) ,b (9 ,3) ,b (9 ,4) ,b (9 ,5) ]) x10 = strcat ([ b (10 ,1) ,b (10 ,2) ,b (10 ,3) ,b (10 ,4) ,b (10 ,5) ]) x11 = strcat ([ b (11 ,1) ,b (11 ,2) ,b (11 ,3) ,b (11 ,4) ,b (11 ,5) ]) x12 = strcat ([ b (12 ,1) ,b (12 ,2) ,b (12 ,3) ,b (12 ,4) ,b (12 ,5) ]) x13 = strcat ([ b (13 ,1) ,b (13 ,2) ,b (13 ,3) ,b (13 ,4) ,b (13 ,5) ]) x14 = strcat ([ b (14 ,1) ,b (14 ,2) ,b (14 ,3) ,b (14 ,4) ,b (14 ,5) ]) x15 = strcat ([ b (15 ,1) ,b (15 ,2) ,b (15 ,3) ,b (15 ,4) ,b (15 ,5) ]) x16 = strcat ([ b (16 ,1) ,b (16 ,2) ,b (16 ,3) ,b (16 ,4) ,b (16 ,5) ]) x =([ x1 ”+” , x2 ”+” , x3 ”+” , x4 ”+” , x5 ”+” , x6 ”+” , x7 ”+” , x8 ”+” , x9 ”+” , x10 ”+” , x11 ”+” , x12 ”+” , x13 ”+” , x14 ”+” , x15 ”+” , x16 ]) disp ( x ) disp ( ’ Reduced e x p r e s s i o n ’ ) disp ( ’A ’ ’BD ’ ’E+AB ’ ’C ’ ’E ’ ’+A ’ ’B ’ ’D+BCD ’ ’+DE ’ ’ ’ ) // E x p r e s s i o n i s d i s p l a y e d //

Scilab code Exa 6.16 Reduce using mapping 1 // Example 6 −16// 2 // Reduce u s i n g mapping // 3 clc 4 // c l e a r s t h e c o n s o l e //

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

0 1 0;1 1 1 0 0 0;1 1 1 0 0 1;1 1 1 0 1 0;1 1 1 1 0 0;1 1 1 1 0 1 ] for i =1: 26 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 if a (i ,6) ==1 then b (i ,6) = ’ F ’ else b (i ,6) = ’ F ’ ’ ’ 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) ,b (1 ,6) ]) 81

57 x2 = strcat ([ b (2 ,1) ,b (2 ,2) ,b (2 ,3) ,b (2 ,4) ,b (2 ,5) ,b

(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 //

Scilab code Exa 6.17 Kmap POS SOP 1 2 3 4 5 6 7 8 9 10 11

// Example 6 −17// // r e d u c e e x p r e s s i o n u s i n g k−map 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

Scilab code Exa 6.18 Minimise expression 1 // Example 6 −18// 2 // M i n i m i s e 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 // Mapping t h e e x p r e s s i o n // 8 disp ( ’Y=m

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 //

Scilab code Exa 6.19 Reduce kmap by POS 1 2 // Example 6 −19// 3 // r e d u c e e x p r e s s i o n u s i n g k−map by f i n d i n g POS// 4 clc 5 // c l e a r s t h e window // 6 clear 7 // 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 // 8 // Mapping t h e e x p r e s s i o n // 9 disp ( ’ C ’ ’D ’ ’ C ’ ’D CD CD ’ ’ ’ ) 10 disp ( ’A ’ ’B ’ ’ 0 0 0 1 ’) 11 disp ( ’AB ’ ’ 1 0 0 0 ’) 12 disp ( ’AB 1 1 0 0 ’) 13 disp ( ’AB ’ ’ 1 1 1 0 ’) 14 disp ( ’ From t h e map , low o u t p u t s f o r 15 16 17 18 19 20 21 22 23 24 25

0 ,1 ,3 ,5 ,6 ,7 ,10 ,14 ,15 ’) // g i v e n l o g i c e q u a t i o n // c =[0 0 0 0;0 0 0 1;0 0 1 1;0 1 0 1;0 1 1 0;0 1 1 1;1 0 1 0;1 1 1 0;1 1 1 1] disp ( c ) for i =1: 9 if c (i ,1) ==1 then d (i ,1) = ’A ’ ’ ’ else d (i ,1) = ’A ’ end if c (i ,2) ==1 then d (i ,2) = ’B ’ ’ ’ 87

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

Scilab code Exa 6.20 Find minimum of expression 1

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 //

Scilab code Exa 6.24 Multiple output equation using mapping 1

// 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

Scilab code Exa 6.25 Multiple output equation using mapping 1 // Example 6 −25// 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( 2 , 3 , 7 , 1 0 , 1 1 , 1 4 )+d ( 1 , 5 , 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( 0 , 1 , 4 , 7 , 1 3 , 1 5 )+d ( 5 , 8 , 1 5 ) ’ ) 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( 1 , 7 , 1 4 )+d ( 5 , 1 5 ) ’ ) 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 1 0 0 ’) 16 disp ( ’AB ’ ’ 0 X 1 0 ’)

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

Scilab code Exa 6.26 Reduce by variable mapping 1 // Example 6 −26// 2 // Reduce by V a r i a b l e Mapping // 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 disp ( ’M=A ’ ’B ’ ’CD ’ ’+A ’ ’B ’ ’CD+AB ’ ’CD ’ ’+AB ’ ’CD+A ’ ’BCD+A 8 9 10 11 12

’ ’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 //

Scilab code Exa 6.27 Reduce by variable mapping 1 // Example 6 −27// 2 // Reduce by V a r i a b l e Mapping // 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 disp ( ’ Z=A ’ ’B ’ ’CDE+A ’ ’BC ’ ’DE ’ ’+A ’ ’BCD+AB ’ ’CD ’ ’ F+ABC ’ ’

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 ( ’m7−E+E ’ ’ ; m14−F+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

Scilab code Exa 6.28 Solve using 3 variable mapping 1 // Example 6 −28// 2 // S o l v e u s i n g 3 V a r i a b l e Mapping // 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 disp ( ’W=Dm2+m6+Dm5+d (m1+D ’ ’m7) ’ ) 8 disp ( ’Dm5 combined w i t h XDm1 ’ ) 9 disp ( ’Dm2 combined w i t h Dm6 ’ ) 10 disp ( ’D ’ ’m6 combined e i t h e r w i t h Dm6 o r XD ’ ’m7 ’ ) 11 disp ( ’ R e s u l t W=B ’ ’CD+ABD ’ ’+BC ’ ’D ’ ) 12 // 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 //

Scilab code Exa 6.29 Reduce by mapping 1 // Example 6 −29// 2 // Reduce by Mapping // 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 disp ( ’R=m0+(E+G)m2+E ’ ’m5+Gm10+Fm13+m14+m15+d (m1+Em4+

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

disp ( ’Em2 c o v e r s Em0 ’ ) disp ( ’E ’ ’m0 c o m b i n e s w i t h m1 ’ ) disp ( ’ R e s u l t R=A ’ ’B ’ ’D ’ ’E+A ’ ’B ’ ’C ’ ’+B ’ ’CD ’ ’G+ABDF+ ABC ’ ) 12 // 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 //

9 10 11

Scilab code Exa 6.30 Reducing expression by Kmap 1 // Example 6 −30// 2 // r e d u c e e x p r e s s i o n u s i n g k−map// 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 // Mapping t h e e x p r e s s i o n // 8 disp ( ’ C ’ ’D ’ ’ C ’ ’D CD CD ’ ’ ’ ) 9 disp ( ’A ’ ’B ’ ’ 1 0 1 1 ’) 10 disp ( ’AB ’ ’ 0 0 1 1 ’) 11 disp ( ’AB 0 1 0 0 ’) 12 disp ( ’AB ’ ’ 1 1 0 1 ’) 13 disp ( ’ From t h e map , h i g h o u t p u t s f o r 14 15 16 17 18 19 20 21 22 23 24 25

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

Scilab code Exa 11.1 Percentage resolution of 5bit DA converter 1 // Example 11 −1// 2 // % R e s o l u t i o n o f a f i v e b i t D/A c o n v e r t e r // 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 n =5 8 // h e r e n i s t h e number o f b i t s // 9 disp ( ’ Max number t h a t can be r e p r e s e n t e d u s i n g 5

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 //

Scilab code Exa 11.2 6 bit analog to digital converter 97

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 //

Scilab code Exa 11.3 Compute the gain of an Opamp 1 // Example 11 −3// 2 // compute g a i n o f an op−amp// 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 Rf =40 8 Rs =5

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 op−amp// 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 op−amp 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 //

Scilab code Exa 11.4 Compute the output voltage // Example 11 −4// // compute o u t p u t v o l t a g e f o r c i r c u i t i n f i g 11 −12// 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 b l e s // R1 =10 R2 =10 R3 =10 Rf =10 E1 =3 E2 = -2 E3 = -4 // 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 v o l t a g e s i n v o l t s a t t h e i n p u t s // 15 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 R1 i n m i l l i amps is : ’) 16 I1 = E1 / R1 17 disp ( I1 ) 1 2 3 4 5 6 7 8 9 10 11 12 13 14

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 //

Scilab code Exa 11.5 Compute output voltage 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

// 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

’)

Related Documents


More Documents from "Rilbert Costa"

January 2021 0
Cap 12 Comp.doc
January 2021 2
Last_christmas_compact
February 2021 1
(n)bucetas Tamanho Gg
February 2021 1