Simplest:
def binary_to_int(value: str) -> int: return int(value, base=2)Own implementation:
def binary_to_int(value: str) -> int: if not set("01").issuperset(value): raise ValueError(f"Not allowed value: {value}") result = 0 for bit, char in enumerate(reversed(value)): if char == "1": result += 2 ** bit return resultThe type hints are not required. I just use them to show which types a function should take and which return types a function has.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!