CHAPTER11 : BINARY LOGIC THEORY AND IMPLEMENTATION

Example E01 : Pg 483

In [1]:
# a
N2 = '101'; # binary ordered sequence 
N = int(N2,base=2) # decimal equivalent of N2
print '%s' %("a")
print'%s %.f'%("The decimal equivqlent of 101 is",N)


# b
N2 = '11011'; # binary ordered sequence 
N = int(N2,base=2); # decimal equivalent of N2
print '%s' %("b")
print '%s %.f' %("decimal equivalent of 11011 = ",N)
a
The decimal equivqlent of 101 is 5
b
decimal equivalent of 11011 =  27

Example E02 : Pg 483

In [2]:
# a
N8 = '432'; # octal number
N = int(N8,base=8); # decimal representation of N8
print '%s' %("a")
print '%s %.f' %("decimal equivalent of 432 = ",N)

# b
N16 = 'C4F'; # hexadecimal number 
N = int(N16,base=16);#hex2dec(N16); # decimal representation of N16
print '%s' %("b")
print '%s %.f' %("decimal equivalent of C4F = ",N) 
a
decimal equivalent of 432 =  282
b
decimal equivalent of C4F =  3151

Example E03 : Pg 488

In [3]:
a="247"
b=oct(247)
print("The octal equivalent of 247 is")
print(b)
dec=247
bina=bin(dec) #binary output
print("\nThe Binary equivalent of 247 is ")
print(bina)
The octal equivalent of 247 is
0367

The Binary equivalent of 247 is 
0b11110111