TITLE: To divide or shift, that is the question PROBLEM: Many programmers write shift operators instead of division. RESPONSE: Steve Clamage (steve@taumet.com), 21 Apr 92 Several posted square-root examples contained code like this: s1=(s+xx/s) >> 1; a = a << 2; b = b << 1; a = a>>2; b = b>>1; I recommend writing a multiply or divide when that is what you mean, rather than writing a shift. Quality compilers will convert the multiply by a literal power of two to a shift if it is faster on the machine, and not otherwise. If you write a shift, it is unlikely that the compiler will convert it to a multiply or divide, even if it were faster. (Right shifting is not equivalent to division if the dividend is negative, so you should be doing these operations with unsigned types in any case.) If it happens that you have a dumb compiler (the code is faster when you code a shift), then go ahead and change the code for that compiler. Hand-optimizing with no knowledge of the characteristics of the compiler and target machine often results in slower code than if you let the compiler do the optimizing.