Divide by 9 without using division or multiplication operator
问题 This question I have tried to solve it but couldn't get any way. Any pointers would be appreciated. Regular subtraction way of doing division is not the intention here, ingenious way of using shifting operator to get this done is the intention. 回答1: Here's a solution heavily inspired by Hacker's Delight that really uses only bit shifts: def divu9(n): q = n - (n >> 3) q = q + (q >> 6) q = q + (q>>12) + (q>>24); q = q >> 3 r = n - (((q << 2) << 1) + q) return q + ((r + 7) >> 4) #return q + (r >