Get the bit at the given position Details: perform bitwise and for the given number and X, Where X is a number with all the bits - zeroes and bit on given position - one. If the result is not equal to 0, then the bit on the given position is 1, else 0. >>> get_bit(0b1010, 0)
(number: int, position: int)
| 75 | |
| 76 | |
| 77 | def get_bit(number: int, position: int) -> int: |
| 78 | """ |
| 79 | Get the bit at the given position |
| 80 | |
| 81 | Details: perform bitwise and for the given number and X, |
| 82 | Where X is a number with all the bits - zeroes and bit on given position - one. |
| 83 | If the result is not equal to 0, then the bit on the given position is 1, else 0. |
| 84 | |
| 85 | >>> get_bit(0b1010, 0) |
| 86 | 0 |
| 87 | >>> get_bit(0b1010, 1) |
| 88 | 1 |
| 89 | >>> get_bit(0b1010, 2) |
| 90 | 0 |
| 91 | >>> get_bit(0b1010, 3) |
| 92 | 1 |
| 93 | """ |
| 94 | return int((number & (1 << position)) != 0) |
| 95 | |
| 96 | |
| 97 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected