We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My reasoning for this question is,
For every binary number in the sequence you need them to be atleast a, which are the most significant bits, like first two bits that add up to 12 (8 + 4) in 12, 13, 14, 15. And these bits must occur in every number of this sequence(which is why and'ing cannot delete them). With certain code blocks you can cut out this part and add trailing zero bits to find the answer. The question is over at this point but if you wonder why we didn't include other bits, you need to constantly flip them to create different numbers this is why they are not consistent and will be deleted by bitwise and. Fun fact: if you have any element which is pow(2, x) and bigger than at least one element in the sequence then your answer will be certainly 0 because none of the below elements will use it's bit. Like 15 and 16, 01111 and 10000, no matter how you and them, the following result will be all zeros, and this will make all problem to collapse. This question only weights your understanding of bits, you don't need any tricks to solve it.
defandProduct(a,b):# Write your code herea=str(bin(a))[2:]b=str(bin(b))[2:]c=0print(a)print(b)foriinrange(len(a)):if(a[i]==b[i]anda[i]=="1"):#tomakesurethatlengthofaandbarethesame,toputitinadifferentway,wewon'tbeaffectedbyleadingzeroesc=ibreakres=""foriinrange(c,len(a)):if(a[i]==b[i]):#cuttingoutthepartthateverynumbermustconsistentlyincluderes=res+a[i]else:breakbinary=resforiinrange(len(a)-len(res)):#fillingtherightsidewithzeroestomakesurethatbin->intconversionwillbeaccomplishedrightbinary=binary+"0"binary=int(binary,2)returnbinary
AND Product
You are viewing a single comment's thread. Return to all comments →
My reasoning for this question is, For every binary number in the sequence you need them to be atleast a, which are the most significant bits, like first two bits that add up to 12 (8 + 4) in 12, 13, 14, 15. And these bits must occur in every number of this sequence(which is why and'ing cannot delete them). With certain code blocks you can cut out this part and add trailing zero bits to find the answer. The question is over at this point but if you wonder why we didn't include other bits, you need to constantly flip them to create different numbers this is why they are not consistent and will be deleted by bitwise and. Fun fact: if you have any element which is pow(2, x) and bigger than at least one element in the sequence then your answer will be certainly 0 because none of the below elements will use it's bit. Like 15 and 16, 01111 and 10000, no matter how you and them, the following result will be all zeros, and this will make all problem to collapse. This question only weights your understanding of bits, you don't need any tricks to solve it.