Max of $\sum_{n=0}^\infty\frac{1}{2^n}h(2^nx)$ Let $h(x)$ be "the sawtooth" function. That is, $h(x)=|x|$ on $[-1,1]$ and satisfies $h(x+2)=h(x)$, in words, zigzags between $y=1$ and $y=0$ of period 2.  It is easy to see that $g(x)=\sum_{n=0}^\infty\frac{1}{2^n}h(2^nx)$ converges.It is continuous but not differentiable. I am asked,

(a) How do we know $g$ attains a maximum value $M$ on $[0, 2]$? What is this
value?

The first part I can do, because I can quote the fact that compact sets are mapped to compact sets, so it must have a max. However, I am at a loss as to how I can find out what that is?

(b) Let $D$ be the set of points in $[0, 2]$ where $g$ attains its maximum. That is $D = \{x ∈ [0, 2] : g(x) = M\}$. Find one point in $D$.

This also throws me. The only way I can see to find such a point would be to something interesting from the definition of $g$, but having such an unpleasant definition, I wouldn't know where to start. I'm surprised that (presumably) part (a) didn't require me to find such a point along the way.
Hints and motivation would be much more appreciated than explicit examples of maxima. This is a question from the book Understanding Analysis.
 A: $0\le h(x) \le 1$ for all $x$. This and the definition of $g$ will give you an upper bound of $g$ without even needing that $g$ is continuous. Then see if you can find a place there $g$ actually takes that upper bound on. What would you need from $h(2^nx)$ for that to happen? If you can't find such a place, then can you use that information to refine your upper bound? And can you find a place where the new upper bound is taken on? etc.
A: Here are some hints to computing this maximum value.
Since the functions deals with powers of two its useful to work in binary. So lets write $$x = a_0.a_1a_2a_3\ldots \equiv \sum_{k=1}^\infty a_k/2^k$$ with $a_i\in\{0,1\}$.
For doing arithmetics on binary numbers it's also useful to note that multiplication/division of $a_1.a_2a_2\ldots$ by a power of $2$ simply corresponds to shifting the position of the decimal digit just as when working with normal decimal numbers and powers of $10$ so e.g. $(a_1.a_2a_2\ldots) / 4 = 0.0a_1a_2a_2\ldots$ and $(a_1.a_2a_3\ldots) \cdot 4 = a_1a_2a_3.a_4\ldots$
Start by using the properties of $h$ to show that we can write $$g(x) = h(a_0.a_1a_2a_3\ldots) + h(a_1.a_2a_3\ldots)/2 + h(a_2.a_3a_4\ldots)/4 + h(a_3.a_4a_5\ldots)/8 + \cdots$$
Notice that the $N$th digit $a_{N-1}$ only enters in the first $N$ terms so we can determine the digits corresponding to the maximum by optimizing the digits recursively. For example you can do a quick estimate and convince yourself that the maximum must start off as $x=1.0a_2\ldots$ or $x=0.1a_2\ldots$.
It turns out that its easier to determine the digits two by two so try to look at any two consecutive terms in the series above
$$h(b_1.b_2b_3\ldots)/2^N + h(b_2.b_3b_4\ldots)/2^{N+1} = [h(b_1.b_2b_3\ldots) + h(b_2.b_3b_4\ldots)/2]\cdot 2^{-N}$$
Consider all the possible digit combinations of $b_1b_2$, i.e. $00$, $11$, $10$ and $01$. Which combinations gives the maximum value for the quantity above? Note that you can compute what $h$ is for these numbers and compare the results (remember that $h(0.bcd\ldots) = 0.bcd\ldots$ and $h(1.bcd\ldots) = 1-0.bcd\ldots$).
From the conclusion you draw above try to write down the $x$'s that correspond to the maximum and find the maximum value.
