# Chapter 15 : DIGITAL ELECTRONICS¶

## Example 15.1 Page No : 492¶

In [2]:
#INPUT DATA
x = 12;			#in decimal form
#CALCULATIONS
y = oct(x);			#converting to octal form
print "Thus octal number is",
print (y);

Thus octal number is 014


## Example 15.2 Page No : 492¶

In [3]:
#INPUT DATA
x1 = 0444;			#in octal form
x2 = 0237;			#in octal form
x3 = 0120;			#in octal form
#CALCULATIONS
print int(x1),int(x2),int(x3);

292 159 80


## Example 15.3 Page No : 493¶

In [4]:
#INPUT DATA
x1 = 112;			#in decimal form
x2 = 253;			#in decimal form
#CALCULATIONS
y1 = hex(x1)			#converting decimal to hexadecimal
y2 = hex(x2)			#converting decimal to hexadecimal
print (y1);
print (y2);

0x70
0xfd


## Example 15.4 Page No : 494¶

In [5]:
#CALCULATIONS
x1 = bin(0x4AB),bin(0x23F) 			#converting hexadecimal to decimal
print (x1);

('0b10010101011', '0b1000111111')


## Example 15.5 Page No : 496¶

In [7]:
#CALCULATIONS
x1 = int('1101',2),int('1100',2)			#converting binary to decimal
x2 = int('1000',2),int('101',2)			#converting binary to decimal
x3 = int('1111',2),int('1001',2)			#converting binary to decimal
y1 = (x1[0])*(x1[1]);			#multiplying
y2 = (x2[0])*(x2[1]);			#multiplying
y3 = (x3[0])*(x3[1]);			#multiplying
z1 = hex(y1)			#converting decimal to hexadecimal
z2 = hex(y2)			#converting decimal to hexadecimal
z3 = hex(y3)			#converting decimal to hexadecimal
print (z1)
print (z2)
print (z3)

0x9c
0x28
0x87


## Example 15.6 Page No : 497¶

In [12]:
import math

#CALCULATIONS
x1 = int('110',2),int('10',2)			#converting binary to decimal
x2 = int('1111',2),int('110',2)			#converting binary to decimal
y1 = (x1[0])/(x1[1]);			#dividing
y2 = (x2[0])/(x2[1]);			#dividing
z1 = bin(y1);			#converting decimal to binary
f,e = math.frexp(y2);			#separting exponent and mantissa
print (f)			#mantissa
print (e)			#exponent
f = f*2;
g = math.floor(f);			#rounding to nearest integer
print (g);
z2 = bin(int(e));			#converting decimal to binary--------->before point part of Resultant binary number
print (z2)
g1 = bin(int(g));			#converting decimal to binary--------->after point part of  Resultant binary number
print (g1)
#NOTE:here floating point decimal cannot be directly converted to binary for second case.Hence computed to binary

0.5
2
1.0
0b10
0b1


## Example 15.7 Page No : 497¶

In [23]:
import math

#CALCULATIONS
#umath.sing 1s complement method
x1 = int('1111',2)			#converting binary to decimal
x = int('1010',2)
x2 = bin(~x)			#1s complement of a number
print (x2)
x3 = int(x2,2)
x4 = x1+x3;
x5 = hex(x4)			#converting decimal to hexadecimal
print (x5)
y = 15;
z =  x4 & y  #biadians(numpy.arcmath.tan((x4,y);			#eliminating carry
z1 = 5    			#setting 1st bit t0 1
z2 = bin(z1)			#converting decimal to binary
print (z2)
#umath.sing normal method
a = int('1111',2),int('1010',2);			#converting binary to decimal
b = a[0]-a[1];			#subtraction
c = bin(b)			#converting decimal to binary
print (c)

-0b1011
0x4
0b101
0b101


## Example 15.8 Page No : 498¶

In [29]:
import math

#CALCULATIONS
#umath.sing 1's complement method
x1 = int('1000',2)			#converting binary to decimal
x = int('1010',2)
x2 = '101'    #dec2bin(bitcmp(x,4))			#1's complement of a number
print (x2)
x3 = int(str(x2),2)
x4 = x1+x3;
x5 = hex(x4)			#converting decimal to hexadecimal
print (x5)
y = 15;
z = x4&y     ;			#eliminating carry
z2 = bin(z)			#converting decimal to binary
print (z2)
#umath.sing normal method
a = int('1000',2),int('1010',2);			#converting binary to decimal
b = a[1]-a[0];			#subtraction
c = bin(b)			#converting decimal to binary
print (c);			#math.since we cannot use dec2base for negative integers,we cannot do (a(1)-a(2)) but we can do (a(2)-a(1)),with '-' sign added before the result.hence 'c' here is actually -'c'

101
0xd
0b1101
0b10


## Example 15.9 Page No : 497¶

In [36]:
#CALCULATIONS
#umath.sing 1's complement method
x1 = int('1111',2)			#converting binary to decimal
x = int('1010',2)
x2 = '101'   #dec2bin(bitcmp(x,4))			#1's complement of a number
print (x2)
x3 = int(x2,2)
x4 = x1+x3+1;
x5 = hex(x4)			#converting decimal to hexadecimal
print (x5)
y = 15;
z = x4 & y;			#eliminating carry
z2 = bin(z)			#converting decimal to binary
print (z2)
#umath.sing normal method
a = int('1111',2),int('1010',2);			#converting binary to decimal
b = a[0]-a[1];			#subtraction
c = bin(b)			#converting decimal to binary
print (c)

101
0x15
0b101
0b101


## Example 15.10 Page No : 497¶

In [37]:
#CALCULATIONS
#umath.sing 1's complement method
x1 = int('1000',2)			#converting binary to decimal
x = int('1010',2)
x2 = '101'  #dec2bin(bitcmp(x,4))			#1's complement of a number
print (x2)
x3 = int(x2,2)
x4 = x1+x3+1;
x5 = hex(x4)			#converting decimal to hexadecimal
print (x5)
#umath.sing normal method
a = int('1000',2),int('1010',2);			#converting binary to decimal
b = a[1]-a[0];			#subtraction
c = bin(b)			#converting decimal to binary
print (c)
#math.since we cannot use dec2base for negative integers,we cannot do (a(1)-a(2)) but we can do (a(2)-a(1)),with '-' sign added before the result.hence 'c' here is actually -'c'

101
0xe
0b10


## Example 15.11 Page No : 500¶

In [38]:
# CALCULATIONS
x1 = int('1001',2)			#converting binary to decimal
x2 = int('0100',2)			#converting binary to decimal
x3 = x1+x2;
if(x3>9):
x3 = x3+6;
z1 = bin(x3)			#converting decimal to binary
else:
z1 = bin(x3,2)			#converting decimal to binary

print (z1)
#note:last 4 bits represent 3 and 5th bit prefixed with 3 bits will look as 1.hence the combined result will be 13

0b10011


## Example 15.12 Page No : 502¶

In [39]:
#CALCULATIONS
print ('given = > Y = (A+AB)')
#given in the question			#
print ('Y = A(1+B)')			#by distributive law
print ('A.1')			#by law 2
print ('A')			#by law 4
print ('given = > Y = (A+A''B)')
print ('(A+A'').(A+B)')			#by distributive law
print ('1.(A+B)')			#by law 6
print ('A+B')			#by law 4
print ('given = >(AB+A''C+BC)')
print ('AB+A''C+BC(A+A'')')
print ('AB+A''C+ABC+A''BC')
print ('AB(1+C)+A''C(1+B)')			#by consensus theorem
print ('AB+A''C')

given = > Y = (A+AB)
Y = A(1+B)
A.1
A
given = > Y = (A+AB)
(A+A).(A+B)
1.(A+B)
A+B
given = >(AB+AC+BC)
AB+AC+BC(A+A)
AB+AC+ABC+ABC
AB(1+C)+AC(1+B)
AB+AC


## Example 15.13 Page No : 503¶

In [40]:
#CALCULATIONS
#for (a)
print ('given = > Y = (A+AB+AB''C)')
print ('Y = A+AB''C')			#by (A+AB = A)------>step 1
print ('A(A+B''C)')			#by distributive law--------->step 2
print ('A(1.(1+B''C))')			#by talking A as common--------->step 3
print ('A.1 = A')			#by 1+B''C = 1--------->step 4
#for (b)
print ('given = > Y = (A''+B)C+ABC')
print ('A''C+BC+ABC')			#by distributive law-------->step 1
print ('A''C+BC(1+A)')			#by taking BC as common--------->step 2
print ('A''C+BC')			#by rule 2 --------->step 3
print ('C(A''+B)')			#taking C as common term-------->step 4
#for (c)
print ('given = > Y = (AB''BCD+AB''CDE+AC'')')
print ('AB''CDE+AC''')			#applying rules 8 and 7 to first and second terms,respectively -------->step 1
print ('A(B''CDE+C'')')			#taking A as common term--------->step 2
print ('A(B''DE+C'')')			#by applying B''CDE+C' = B'DE+C'--------->step 3

given = > Y = (A+AB+ABC)
Y = A+ABC
A(A+BC)
A(1.(1+BC))
A.1 = A
given = > Y = (A+B)C+ABC
AC+BC+ABC
AC+BC(1+A)
AC+BC
C(A+B)
given = > Y = (ABBCD+ABCDE+AC)
ABCDE+AC
A(BCDE+C)
A(BDE+C)


## Example 15.17 Page No : 513¶

In [41]:
#CALCULATIONS
print ('((((A+C''))''(BD''))''.((A+C'').(BD''))'')''')			#------>step 1
print ('((A+C'')+((BD'')'').((A+C)''+(BD'')''))''')			#------>step 2
print ('((A+C'')+(BD'')'').((A+C'')''+(BD'')'')''')			#------>step 3
print ('((BD'')''+((A+C'')((A+C''))'')''')			#------>step 4
print ('(BD'')'')''')			#------>step 5
print ('BD''')			#------>step 6

((((A+C))(BD)).((A+C).(BD)))
((A+C)+((BD)).((A+C)+(BD)))
((A+C)+(BD)).((A+C)+(BD))
((BD)+((A+C)((A+C)))
(BD))
BD


## Example 15.19 Page No : 519¶

In [42]:
#CALCULATIONS
#The adjacent cells that can be combined together are the cells 000 and 100 and the cell 011 and 111
#By combining the adjacent cells,we get
print ('((A''+A)B''C'')+(A''+A)BC)')			#------>step 1
print ('(B''C'')+(BC)')			#------>step 2

((A+A)BC)+(A+A)BC)
(BC)+(BC)


## Example 15.20 Page No : 519¶

In [43]:
#CALCULATIONS
print ('(B''C''D'')+(BC''D)')

(BCD)+(BCD)