pydsa.digits¶
to_digits ¶
to_digits(
num: Union[int, str],
reverse: bool = False,
base: int = 10,
) -> List[int]
The digits of num in the given base as ints, most significant first.
With reverse=True the least significant digit comes first, so digit i is the coefficient of base**i. A negative int loses its sign. A str is read one character at a time, so leading zeros are kept; base=2 gives the bits.
Source code in pydsa/digits.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
to_int ¶
to_int(
digits: List[int], reverse: bool = False, base: int = 10
) -> int
The int whose digits in the given base are the list, most significant first.
With reverse=True the list is read least significant first, the inverse of to_digits(num, reverse=True). An empty list is 0. base=2 reads bits.
Source code in pydsa/digits.py
30 31 32 33 34 35 36 37 38 39 40 | |
even ¶
even(n: int) -> bool
True when n is even.
Source code in pydsa/digits.py
43 44 45 | |
odd ¶
odd(n: int) -> bool
True when n is odd.
Source code in pydsa/digits.py
48 49 50 | |