A different approach - no vba
abcdefghijklmnopq1bit151413121110987654321023276816384819240962048102451225612864321684213111111111111111111111111878787872323773104=if(b6=1,a3-b2,a3)56=c3,1,0)">0=d3,1,0)">0=e3,1,0)">0=f3,1,0)">0=g3,1,0)">0=h3,1,0)">1=i3,1,0)">0=j3,1,0)">0=k3,1,0)">0=l3,1,0)">1=m3,1,0)">0=n3,1,0)">1=o3,1,0)">0=p3,1,0)">1=q3,1,0)">1=r3,1,0)">17=b2,1,0)">=if(a3>=b2,1,0)
formula listed below the start of cell/row so visible in this copy. Formulas copied across b3 thru q3 and b6 thru q3. Number to parse goes in a3, row 6 gives bits. Formulas could probably be combined and row 2 numbers hardcoded into formula if you need to get to one line.
Mike