The solution given so far,

**2^n - n(n+1)/2 - 1,** assumes that a binary string can begin with a zero.

I choose to assume that all binary strings except for 0 must begin with a 1. Under this assumption, we can apply the same formula to the string of (n-1) digits after the leading 1. This gives a solution of

**2^(n-1) - n(n-1)/2 - 1. ** This formula works even when n = 1.