there's a faster algorithm

start with n = 1

if it's all zeroes the number is 0

ignore all digits up to and including the first 1 (left-to-right)

when you see a zero, 2n

when you see a one, 2n + 1

so 00000101:

n = 1 (1)01

n = 2 1(0)1

n = 4 + 1 10(1)

n = 5