Chapter 10 - Combinational Logic Systems

Example 10_1 Page No. 308

In [3]:
x=72##given value in Decimal
print "Decimal number=",(x)
Str=bin(x)[2:]
print "Eqivalent Binary number=",(Str)#Binary value
Decimal number= 72
Eqivalent Binary number= 1001000

Example 10_2 Page No. 308

In [4]:
x='1001000'##Binary value
print "Binary number=",(x)
Str=int(x,2)
print "Eqivalent Decimal number=",(Str)#decimal value
Binary number= 1001000
Eqivalent Decimal number= 72

Example 10_3 Page No. 308

In [11]:
b='1001000'#
print "Binary number=",(b)#Binary value
d=int(b,2)# Binary to decimal value
o=oct(d)# Decimal to octal
print "Eqivalent Octal number=",(o)
Binary number= 1001000
Eqivalent Octal number= 0110

Example 10_4 Page No. 309

In [12]:
x=72#
print "Decimal number=",(x)#Decimal value
Str=oct(x)#decimal to octal
print "Eqivalent Octal number=",(Str)
Decimal number= 72
Eqivalent Octal number= 0110

Example 10_5 Page No. 309

In [16]:
x='110'#
print "Octal number=",(x)#octal value
y=int(x,8)# octal to decimal
Str=bin(y)[2:] #decimal to binary
print "Eqivalent Binary number=",(Str)
Octal number= 110
Eqivalent Binary number= 1001000

Example 10_6 Page No. 309

In [17]:
x='110'#
print "Octal number=",(x)# octal value
Str=int(x,8)#octal to decimal
print "Eqivalent Decimal number=",(Str)
Octal number= 110
Eqivalent Decimal number= 72

Example 10_7 Page No. 309

In [19]:
x=72#
print "Decimal number=",(x) #decimal value
Str=hex(x)[2:]# decimal to hexadecimal
print "Eqivalent Hexadecimal number=",(Str)
Decimal number= 72
Eqivalent Hexadecimal number= 48

Example 10_8 Page No. 310

In [20]:
h='48'#
print "Hexadecimal number=",(h)# value in hexadecimal
d=int(h,16)#hexadecimal to decimal
print "Eqivalent Decimal number=",(d)
Hexadecimal number= 48
Eqivalent Decimal number= 72

Example 10_9 Page No. 310

In [22]:
h='48'#
print "Hexadecimal number=",(h) #hexadecimal
d=int(h,16)# converting hexadecimal to decimal
Str=bin(d)[2:]# converting decimal to binary
print "Eqivalent Binary number=",(Str)
Hexadecimal number= 48
Eqivalent Binary number= 1001000

Example 10_10 Page No. 310

In [24]:
x='1001000'#
print "Binary number=",(x)#binary value
d=int(x,2)#binary to decimal
h=hex(d)[2:] #decimal to hexa decimal
print "Eqivalent hexadecimal number=",(h)
Binary number= 1001000
Eqivalent hexadecimal number= 48

Example 10_11 Page No. 311

In [34]:
#for two digit decimal value to convert into BCD
#for two digit decimal value to convert into BCD
x='72'#
digits = [int(c) for c in x]
zero_padded_BCD_digits = [format(d, '03b') for d in digits]
print "Eqivalent BCD of 72 = ",
print ''.join(zero_padded_BCD_digits)
Eqivalent BCD of 72 =  111010