#! /usr/bin/env python from typing import Final import sys n = int(sys.argv[1]) power = 1 LIMIT: Final[int] = n // 2 # find the largest power of 2, which is less than or equal to n/2 while power <= LIMIT: power *= 2 binary_presentation = "" while power > 0: if n < power: binary_presentation += "0" else: binary_presentation += "1" n -= power power //= 2 print(binary_presentation)