#INPUT DATA
x = 12; #in decimal form
#CALCULATIONS
y = oct(x); #converting to octal form
print "Thus octal number is",
print (y);
#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);
#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);
#CALCULATIONS
x1 = bin(0x4AB),bin(0x23F) #converting hexadecimal to decimal
print (x1);
#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)
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
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)
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'
#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)
#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'
# 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
#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')
#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
#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
#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
#CALCULATIONS
print ('(B''C''D'')+(BC''D)')