Re: division by 7efficiently



On Feb 1, 2:28 pm, "Krypto" <krypto.wiz...@xxxxxxxxx> wrote:
The correct answer as told to me by a person is

(N>>3) + ((N-7*(N>>3))>>3)

The above term always gives division by 7


N >> 3 is the same as dividing the number by eight so you have that
(N>>3) + ((N-7*(N>>3))>>3) = N/8 + (N - 7(N/8))/8 = N/8 + N/8 - 7N/64
= 2N/8 - 7N/64 = (16N - 7N) / 64 = 9/64 N.

9/64 = 0.140625
1/7 = 0.14285714285714285...

Close, but no cigar.


.