Example 11 For non-negative integers $n, f(n)$ is determined by $f(0)=0, f(1)=1, f(n)$ $=f\left(\left[\frac{1}{2} n\right]\right)+n-2\left[\frac{1}{2} n\right]$, find the maximum value of $f(n)$ when $0 \leqslant n \leqslant 1997$.
Solution: Represent $n$ in binary, let $n=\left(a_{k} a_{k-1} \cdots a_{1}\right)_{2}$, where $a_{i}(i=1,2$, $\cdots, k$ ) is 0 or 1, then we have
$$
\left[\frac{1}{2} n\right]=\left(a_{k} a_{k-1} \cdots a_{2}\right)_{2}, n-2\left[\frac{1}{2}\right]=a_{1} \text {. }
$$

Thus, $f(n)=f\left(\left(a_{k} a_{k-1} \cdots a_{2} a_{1}\right)_{2}\right)$
$$
\begin{array}{l}
=f\left(\left(a_{k} a_{k-1} \cdots a_{2}\right)_{2}\right)+a_{1} \\
=f\left(\left(a_{k} a_{k-1} \cdots a_{3}\right)_{2}\right)+a_{2}+a_{1} \\
=\cdots=f(0)+a_{k}+a_{k-1}+\cdots+a_{2}+a_{1}
\end{array}
$$
$=n$ in the sum of the digits in binary.
Since $2^{10}<1997<2^{11}-1$, in binary, the number of digits of $n$ $\leqslant 11$, and when the number of digits is 11, the digits are not all 1: Therefore, when $n \leqslant 1997$, the maximum value of $f(n)$ is 10 (the $n$ that makes $f(n)$ 10 includes $2^{10}-1,2^{10}+2^{9}-1,2^{10}+2^{9}+2^{8}-1$ etc.).