This is [Exercise 9.M](https://books.google.com/books?id=Cqk5AAAAIAAJ&pg=PA13) from A. C. M. van Rooij, W. H. Schikhof: *A Second Course on Real Analysis*.$\newcommand{\dcc}[1]{\lfloor#1\rfloor}$

> **Exercise 9.M.** (Another function that maps every interval onto $[0,1]$) For $x\in[0,1]$ let
$0.x_1x_2x_3\dots$ be the standard dyadic development of $x-\dcc x$:
$$x_n=\dcc{2^n x}-2\dcc{2^{n-1}x}$$
where $\dcc x$ is the entire part of $x$. Define $\phi\colon{\mathbb R}\to{\mathbb R}$ by
$$\phi(x)=\limsup\limits_{n\to\infty}\frac{x_1+x_2+\dots+x_n}n$$
Show that $\phi$ maps every interval *onto* $[0,1]$. (Hint: First show that $\phi(x)=\phi(y)$ if there exist $p,q\in\mathbb N$ such that
$x_p=y_q$, $x_{p+1}=y_{q+1}$, $x_{p+2}=y_{q+2}$, etc., so that it suffices to show that $\phi$ maps $[0,1]$ onto $[0,1]$. Now let $t\in[0,1]$, $t\ne1$. Find an $x\in[0,1]$ such that $x_1+\dots+x_n=\dcc{nt}$ for every $n$ and prove that $\phi(x)=t$. Finally, find an $x$ with $\phi(x)=1$.)

The same function appears as [Problem 1.3.29](https://books.google.com/books?id=UBmIAwAAQBAJ&pg=PA159) in Kaczor, Nowak: *Problems in Mathematical Analysis Vol II* and it is given also in an answer here: [Can we construct a function $f:\mathbb{R} \rightarrow \mathbb{R}$ such that it has intermediate value property and discontinuous everywhere?](https://math.stackexchange.com/q/21812#44285). The same function was also used by Andrés E. Caicedo as an example of a function which is of Baire class 2 but not of Baire class 1: [Examples of Baire class 2 functions](https://math.stackexchange.com/q/614429#614435). (See also his blog post: [414/514 Examples of Baire class two functions](https://andrescaicedo.wordpress.com/2014/11/03/414514-examples-of-baire-class-two-functions/))

As all functions $x_n$ are Borel measurable, so is the function $\phi$.

For this function, the image of a non-trivial interval is only the interval $[0,1]$. But we can get function which maps this onto reals by composition with some <s>continuous</s> Borel surjection from a unit interval to reals.