There's absolutely a faster way of doing this using bit manipulation. I'll write a simple function to prove it, although I'm busy now but will definitely show u why I said bit manipulation is faster
It is unintuitive but David is right. The thing to observe is a 512 bit number puts you into a scenario where every int is an array. Operations like & are surprisingly costly and each allocates. But python’s long_format_binary is implemented in C with what looks like a single allocation: the string.
I'm very excited to see your solution
def reversed(x: int) -> int: num = 0 for _ in range (512): num = (num << 1) | (x & 1) x >>= 1 return num though, it is longer but is faster than having to convert num to binary string and then reverse it becs it directly manipulates the individual bits. I may be wrong