Digit counts

The number of black squares on row n in the pattern shown here is given by DigitCount[n,2,1] and is plotted below. This function appeared on page 870 in the discussion of binomial coefficients modulo 2, and will appear again in several other places in this book. Note the inequality 1<=DigitCount[n,2,1] <= Log[2, n]. Formulas for DigitCount[n,2,1] include n-IntegerExponent[n!, 2] and

2n - Log[2, Denominator[Derivative[n][(1 - #)^(-1/2) &][0]/n!]]

Straightforward generalizations of DigitCount can be defined for integer and non-integer bases and by looking not only at the total number of digits but also at correlations between digits. In all cases the analogs of the picture below have a nested structure.