-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremBin.py
More file actions
31 lines (30 loc) · 744 Bytes
/
Copy pathremBin.py
File metadata and controls
31 lines (30 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def rem31(numerator):
modulus = numerator
while numerator > 31:
modulus = 0
while numerator:
modulus += numerator & 31
numerator >>= 5
numerator = modulus
if modulus == 31:
return 0
return modulus
def rem62(numerator):
x = 31 * (numerator % 2) + 32 * (rem31(numerator))
return x % 62
"""
unsigned int n; // numerator
const unsigned int s; // s > 0
const unsigned int d = (1 << s) - 1; // so d is either 1, 3, 7, 15, 31, ...).
unsigned int m; // n % d goes here.
for (m = n; n > d; n = m)
{
for (m = 0; n; n >>= s)
{
m += n & d;
}
}
// Now m is a value from 0 to d, but since with modulus division
// we want m to be 0 when it is d.
m = m == d ? 0 : m;
"""