Example 13 (1989 Irish Mathematical Olympiad) The function $f$ is defined on the set of natural numbers and satisfies the following conditions:
(1) $f(1)=1$;
(2) $f(2 n)=f(n), f(2 n+1)=f(2 n)+1(n \geqslant 1)$.
For $1 \leqslant n \leqslant 1989$, find the maximum value $u$ of $f(n)$, and determine how many $n(1 \leqslant n \leqslant 1989)$ satisfy $f(n)=n$.
Let's prove: If $a$ is a number represented in binary, then $f(a)$ is the sum of the digits of $a$. Indeed, when $a$ is a single-digit number, $f(1)=1$, the proposition holds; assuming the proposition holds for an $n$-digit number $a$, i.e.,
when $a=a_{1} 2^{n-1}+a_{1} 2^{n-2}+\cdots+a_{n-1}$, $f(a)=a_{0}+a_{1}+\cdots+a_{n-1}$.
For a binary number with $n+1$ digits, there are two cases:
(i) $2 a=a_{0} 2^{n}+a_{1} 2^{n-1}+\cdots+a_{n-1} \cdot 2$, the sum of its digits is $a_{0}+a_{1}+\cdots+a_{n-1}=f(a)$, and $f(2 a)=f(a)$, i.e., the sum of the digits of $f(2 \cdot a)$ is the sum of the digits of $2 a$.
(ii) $2 a+1=a_{0} 2^{n}+a_{1} 2^{n-1}+\cdots+a_{n-1} \cdot 2+1$, the sum of its digits is
$a_{0}+a_{1}+\cdots+a_{n-1}+1=f(a)+1$.
Also, $f(2 a+1)=f(2 a)+1=f(a)+1$, i.e., $f(2 a+1)$ is also the sum of the digits of $2 a+1$.
Thus, we have proven by mathematical induction that when $a$ is a number represented in binary, $f(a)$ is the sum of the digits of $a$.
Since $2^{10}+2^{9}+\cdots+2+1=2^{11}-1=2047>1989$, and
$1989=2^{10}+2^{9}+2^{8}+2^{7}+2^{6}+2^{2}+1=(11111000101)_{2}$,

thus $M_{\max }=10$.
The binary representation of numbers not exceeding 1989 in decimal is a ten-digit number, $(1111111111)_{2}=1023$ and four eleven-digit numbers $(10111111111)_{2}=1535,(11011111111)_{2}=1791,(11101111111)_{2}=1919,(11110111111)_{2}=1983$.
Therefore, $M_{\max }=10$, and when $1 \leqslant n \leqslant 1989$, there are 5 values of $n$ such that $f(n)=10$.