Is the bit at position set? Details: Shift the bit at position to be the first (smallest) bit. Then check if the first bit is set by anding the shifted number with 1. >>> is_bit_set(0b1010, 0) False >>> is_bit_set(0b1010, 1) True >>> is_bit_set(0b1010, 2) False
(number: int, position: int)
| 54 | |
| 55 | |
| 56 | def is_bit_set(number: int, position: int) -> bool: |
| 57 | """ |
| 58 | Is the bit at position set? |
| 59 | |
| 60 | Details: Shift the bit at position to be the first (smallest) bit. |
| 61 | Then check if the first bit is set by anding the shifted number with 1. |
| 62 | |
| 63 | >>> is_bit_set(0b1010, 0) |
| 64 | False |
| 65 | >>> is_bit_set(0b1010, 1) |
| 66 | True |
| 67 | >>> is_bit_set(0b1010, 2) |
| 68 | False |
| 69 | >>> is_bit_set(0b1010, 3) |
| 70 | True |
| 71 | >>> is_bit_set(0b0, 17) |
| 72 | False |
| 73 | """ |
| 74 | return ((number >> position) & 1) == 1 |
| 75 | |
| 76 | |
| 77 | def get_bit(number: int, position: int) -> int: |
nothing calls this directly
no outgoing calls
no test coverage detected