Decompose non-negative int a into base 2**n Input: a is a non-negative integer Output: List of the digits of a in base 2**n in little-endian order, meaning the most significant digit is last. The most significant digit is guaranteed to be non-zero. If a is 0 t
(a, n)
| 463 | |
| 464 | |
| 465 | def _int2digits(a, n): |
| 466 | """Decompose non-negative int a into base 2**n |
| 467 | |
| 468 | Input: |
| 469 | a is a non-negative integer |
| 470 | |
| 471 | Output: |
| 472 | List of the digits of a in base 2**n in little-endian order, |
| 473 | meaning the most significant digit is last. The most |
| 474 | significant digit is guaranteed to be non-zero. |
| 475 | If a is 0 then the output is an empty list. |
| 476 | |
| 477 | """ |
| 478 | a_digits = [0] * ((a.bit_length() + n - 1) // n) |
| 479 | |
| 480 | def inner(x, L, R): |
| 481 | if L + 1 == R: |
| 482 | a_digits[L] = x |
| 483 | return |
| 484 | mid = (L + R) >> 1 |
| 485 | shift = (mid - L) * n |
| 486 | upper = x >> shift |
| 487 | lower = x ^ (upper << shift) |
| 488 | inner(lower, L, mid) |
| 489 | inner(upper, mid, R) |
| 490 | |
| 491 | if a: |
| 492 | inner(a, 0, len(a_digits)) |
| 493 | return a_digits |
| 494 | |
| 495 | |
| 496 | def _digits2int(digits, n): |
no test coverage detected
searching dependent graphs…