'How to get a bit from a byte without bitwise operations
i want to know if there's a way to get a specific bit from a byte, without bitwise operators.
I think i've got a clue, i imagine a way to do it with square root or power... and mod.
Thank you beforehand.
Solution 1:[1]
Example using Python:
>>> def getbit(i, n):
... return i // 2 ** n % 2
...
>>> for i in range(8): print(f"Bit {i}: {getbit(0b10101111, i)}")
...
Bit 0: 1
Bit 1: 1
Bit 2: 1
Bit 3: 1
Bit 4: 0
Bit 5: 1
Bit 6: 0
Bit 7: 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HTF |
