Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
lambda n:inteval((bin(n).rstrip("0")+"01"*n)[:len(bin(n))],2)
Try it online!Try it online!
Not really happy with this yet, but I really didn't want to use the formula... -2 thanks to Rod. -1 thanks to Jonathan Frech.
lambda n:int((bin(n).rstrip("0")+"01"*n)[:len(bin(n))],2)
Try it online!
Not really happy with this yet, but I really didn't want to use the formula... -2 thanks to Rod.
lambda n:eval((bin(n).rstrip("0")+"01"*n)[:len(bin(n))])
Not really happy with this yet... -2 thanks to Rod.
lambda n:int((bin(n).striprstrip("0")+"01"*n)[1[:len(bin(n))-1]],2)
lambda n:int((bin(n).strip("0")+"01"*n)[1:len(bin(n))-1],2)
Not really happy with this yet...