5

Possible Duplicate:
What's the fastest way to divide an integer by 3?

Assume the dividend fits into a single word of memory, and that you can use all standard instructions besides division.

Community
  • 1
  • 1
jonderry
  • 23,013
  • 32
  • 104
  • 171
  • Add this one to the annals of stupid interview questions. – jason Jan 06 '11 at 02:17
  • It's not a duplicate of that, though it's related. The other question asked if it's possible to divide by 3 faster without using the division operator than with using it. The accepted answer is that it's not. Neither the question nor that answer duplicates this question. – Don Roby Jan 06 '11 at 02:21
  • 1
    Ah, didn't see that question in my original search. Multiplying by 0x55555556 seems to be the way to go. It seems to be equivalent to multiplying by the binary representation of 1/3, rounded up so that you get the correct answer when the dividend is divisible by 3. – jonderry Jan 06 '11 at 04:15

0 Answers0