Example 3 Let $g(n)$ denote the greatest odd divisor of the natural number $n$, for example, $g(3)=3$, $g(14)=7$, etc. Find the value of $g(1)+g(2)+g(3)+\cdots+g\left(2^{n}\right)$.
Let $S_{n}=g(1)+g(2)+\cdots+g\left(2^{n}\right)$, then $S_{1}=g(1)+g(2)=2$.
By the problem, when $k$ is an integer, $g(2 k)=g(k)$; when $k$ is odd, $g(k)=k$. Therefore, for natural numbers $n \geqslant 2$, we have
$$
\begin{array}{l}
S_{n}=\left[g(1)+g(3)+\cdots+g\left(2^{n}-1\right)\right] \\
+\left[g(2)+g(4)+\cdots+g\left(2^{n}\right)\right] \text {. } \\
=\underbrace{1+3+\cdots+\left(2^{n}-1\right)}_{2^{n-1} \uparrow=2^{\prime}}+\left[g(1)+g(2)+\cdots+g\left(2^{n-1}\right)\right] \\
=4^{n-1}+S_{n-1} \text {, } \\
\end{array}
$$

i.e., $S_{n}-S_{n-1}=4^{n-1}(n \geqslant 2)$.
$$
\text { Hence } \begin{aligned}
S_{n} & =S_{1}+\left(S_{2}-S_{1}\right)+\left(S_{3}-S_{2}\right)+\cdots+\left(S_{n}-S_{n-1}\right) \\
& =2+4^{1}+4^{2}+\cdots+4^{n-1}=\frac{1}{3}\left(4^{n}+2\right) .
\end{aligned}
$$