Extract lowest bits
Your task
A device packs several fields into one non-negative integer, and the lowest k bits hold a rolling counter. Given the packed value n (0 <= n < 2^31) and a width k (0 <= k <= 30), return the counter: the integer formed by the lowest k bits of n. When k is 0 the counter is empty, so return 0. For example, n = 173 (binary 10101101) with k = 4 returns 13 (binary 1101).
Examples
low_bits_value(n: int, k: int) -> intExample 1
Input
low_bits_value(173, 4)Output
13Example 2
Input
low_bits_value(37, 5)Output
5