#Given
d=37; #Given decimal number
#Calculation
b=int(bin(d)[2:]); #Equivalent Octal number
#Result
print("The equivalent binary number=%s."%b);
#Given
d=23; #Given decimal number
#Calculation
b=int(bin(d)[2:]); #Equivalent Octal number
#Result
print("The equivalent binary number=%d."%b);
#Given
b=0b110001; #Given binary number
#Calculation
d=int(b); #Equivalent decimal number
#Result
print("Equivalent decimal number=%d."%d);
#Given
d1=76; #Given decimal number
d2=255; #Given decimal number
d3=372; #Given decimal number
#Calculation
o1=int(oct(d1)[1:]); #Equivalent octal number
o2=int(oct(d2)[1:]); #Equivalent octal number
o3=int(oct(d3)[1:]); #Equivalent octal number
#Result
print("(i) Equivalent octal number=%d."%o1);
print("(ii) Equivalent octal number=%d."%o2);
print("(iii) Equivalent octal number=%d."%o3);
#Given
o=24.6; #Given octal number
#Calculation
o_f=o%1; #Floating part of octal number
o_i=(int)(o-(o%1)); #Integer part of octal number
d=int(str(o_i),8); #Equivalent decimal number
s=str(o_f); #String value of floating part
i=2
while(i<len(s)):
d=d+int(s[i])*8**-(i-1);
i+=1;
#Result
print("Equivalent decimal number=%.2f."%d);
#Given
d=177; #Given decimal number
#Calculation
o=oct(d)[1:]; #Equivalent octal number
b="";
for i in o:
bo=bin(int(i))[2:]; #Binary of individual octal digit
b=b+(("0" if len(bo)==2 else ("00" if len(bo)==1 else"")) +bo); #Equivalent binary number
#Result
print("Equivalent octal number=%s."%o);
print("Equivalent binary number=%s."%b);
#Given
d=541; #Given decimal number
#Calculation
h=hex(d)[2:]; #Equivalent hexadecimal number
#Result
print("Equivalent hexadecimal number=%s."%h);
hex_to_dec={'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'a':10,'b':11,'c':12,'d':13,'e':14,'f':15};
#Given
d=378; #Given decimal number
#Calculation
h=hex(d)[2:]; #Equivalent Hexadecimal number
b="";
for i in h:
bh=bin(hex_to_dec[i])[2:]; #Binary of individual hexadecimaldigit
b=b+(("0" if len(bh)==3 else ("00" if len(bh)==2 else ("000" if len(bh)==1 else "")))+bh); #Equivalent binary number
#Result
print("Equivalent hexadeciaml number=%s."%h);
print("Equivalent binary number=%s."%b);
#Given
h=0xB2F; #Given hexadecimal number
#Calculation
o=oct(h)[1:]; #Equivalent octal number
#Result
print("Equivalent octal number=%s."%o);
#Given
BCD="0100 0000 0010" #Given BCD string
BCD_split=BCD.split(" "); #Splitting th binary string into individual BCD
d=0;
for i in range(len(BCD_split),0,-1):
d+=int(BCD_split[len(BCD_split)-i],2)*10**(i-1);
#Result
print("The equivalent decimal =%d."%d);
print("Boolean Expression obtained from the circuit: \n Y'=A+B \n Y=((A+B).A)");
print("Truth Table:");
print("a\tb\tY'=A+B\t Y=Y'.A");
for b in range(0,2):
for a in range(0,2):
Y_dash=1 if a or b else 0;
Y=1 if Y_dash and a else 0;
print("%d\t%d\t%d\t %d"%(a,b,Y_dash,Y));
print("Boolean Expression obtained from the circuit: \n Y'=A'.B \n Y=Y'+B'");
print("Truth Table:");
print("A\tB\tA'\tY'=A'.B\t B'\tY=Y'+B'");
for b in range(0,2):
for a in range(0,2):
a_dash=1 if not a else 0;
b_dash=1 if not b else 0;
Y_dash=1 if a_dash and b else 0;
Y=1 if Y_dash or b_dash else 0;
print("%d\t%d\t%d\t%d\t %d\t%d"%(a,b,a_dash,Y_dash,b_dash,Y));