BLUE
Profile banner
F
FrankieWilson
@frankiewilson.bsky.social
A s.e
2 followers4 following33 posts
Ffrankiewilson.bsky.social

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

3

JCplc.joncaruana.com

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.

0
DBretr0.id

I'm very excited to see your solution

0
Ffrankiewilson.bsky.social

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

1
Profile banner
F
FrankieWilson
@frankiewilson.bsky.social
A s.e
2 followers4 following33 posts