You are on page 1of 1

write a program for multiplying 2 with 8?

Ans: We may think that its a simpler multiplication and we just do it as C=A*B w hile writing the program But this is a big mistake, think once why the interviewer asked such a simple qu estion. Its because the program is not that simple u hav to think logically how to answer it.Now lets get into the answer 1st of all we know that for multiplyin g two numbers it takes more cycles than that of the addition and subtraction we can reduce the cycles by using bitwise shift operations as we know that shifting a number takes much fewer cylces compared to multiplication n division.So while writing a c prgm the most im portant thing to remember is the computation time must be reduced to as minimum as possible.So the techinque is 1000*0010=> 2<<3 means shifting 2 to left by 3 times as 8=2^(3) or else 8<<1 as 2=2^1 1000<<1 =10000 which means 10000=16 is the answer.As shifting operation takes only one cycle so u hav 2 write prgm like this int a=2, c=8, b=3 c=a<<b printf("%d, c") u can use the same principle for divison too divide 16 by 4 means 4=2^(2) that means 16>>2 10000>>2 =100 "4" is the answer