>> is a bit shift. Each bit is shifted to the right, essentially divides the number 2.
Therefore, (length >> 3) length/8 (rounded), and (length >> 6) - length/64 .
Take (length/8)+(length/64) about length*(1/8+1/64) length*0.140625 length*(1/8+1/64) = length*0.140625 (approximately)
1/7 = 0.142857...
+1 at the end can be divided by +0.5 for each member, so length/8 rounded to the nearest (instead of down), and length/64 also rounded to the nearest.
In general, you can easily approximate 1/y , where y = 2^n+-1 with a similar bit shift approximation.
Infinite geometric series:
1 + x + x^2 + x^3 + ... = 1 / (1 - x)
Multiplication by x:
x + x^2 + x^3 + ... = x/(1 - x)
And substituting x = 1/2^n
1/2^n + 1/2^2n + 1/2^3n + ... = (1/2^n) / (1 - 1/2^n) 1/2^n + 1/2^2n + 1/2^3n + ... = (1/2^n) / ((2^n - 1)/2^n) 1/2^n + 1/2^2n + 1/2^3n + ... = 1 / (2^n - 1)
This approaches y = 2^n - 1 .
To get closer to y = 2^n + 1 , replace x = -1/2^n .
- 1/2^n + 1/2^2n - 1/2^3n + ... = (-1/2^n) / (1 + 1/2^n) 1/2^n - 1/2^2n + 1/2^3n - ... = (1/2^n) / ((2^n + 1)/2^n) 1/2^n - 1/2^2n + 1/2^3n - ... = 1 / (2^n + 1)
Then simply crop the endless row to the desired precision.
source share