Result [link]

AC

Code [DL]

s/^/0000a/
:l
s/1001a/1100a/g
s/1000a/1011a/g
s/0111a/1010a/g
s/0110a/1001a/g
s/0101a/1000a/g
s/a\(.\)/\1a/g
s/0\([01]\{4\}a\)/\1/
s/1\([01]\{4\}a\)/0001a\1/
/[^a]$/b l
s/^0+a//
s/0000a/0/g
s/0001a/1/g
s/0010a/2/g
s/0011a/3/g
s/0100a/4/g
s/0101a/5/g
s/0110a/6/g
s/0111a/7/g
s/1000a/8/g
s/1001a/9/g

stdin

1101001111011100001100010011110101111100011110100100011111110101111000100101000101111100101010111010

stdout

1049080532524762204120217537210

stderr

strace