Calculate the sum of Identical uniformly distributed random variables, can't understand a specific step from the textbook I am trying to study from a textbook and encountered the following example:

No matter what I tried, I didn't understand the last step. How did the author change the limits of the integral in such way?
He than continues:

Which is even more odd to me. Where did these ranges come from? 
I'd really appreciate your help. I am a probability newbie (obvious ha?) and really wish to learn.
Thanks!
 A: We want to compute
$$\int_{0}^{1} f_{X}(a-y) dy$$
Well, $$f_{X}(a-y) = \begin{cases}1 & 0 < a-y < 1 \\ 0 & \text{otherwise}\end{cases}$$
If $0 \le a \le 1$, then $a-y<1$ for all $y$ in the region. And $a-y > 0$ 
when $y < a$. So, we have 
$$f_{X}(a-y) = \begin{cases}1 & 0 < y < a\\ 0 & a < y < 1\end{cases}$$
So that 
$$\int_{0}^{1} f_{X}(a-y) dy = \int_{0}^{a} 1 \,dy + \int_{a}^{1} 0 \,dy = a. $$
The case for $1 \le a \le 2$ is similar. 
A: 
No matter what I tried, I didn't understand the last step. How did the author change the limits of the integral in such way?

We have $f_{X+Y}(a) = \int_0^1 f_X(a-y)\,dy$, where $f_X(t) = \begin{cases}1&0< t< 1\\ 0&\text{otherwise}\end{cases}$. With a piecewise defined function like this or anything with an absolute value, the way to handle an integral is to split the interval everywhere we change formulas. So then, we look for $y\in (0,1)$ such that $a-y=0$ or $a-y=1$. That means either $y=a$ or $y=a-1$, and at most one of these will be in the interval. So then, four relevant regions:


*

*$a \le 0$. Then, for all $y\in [0,1]$, $f_X(a-y)=0$.The integral becomes $\int_0^1 0\,dy = 0$.

*$0<a\le 1$. We have a point in the interval with $y=a$, so we split there:
$$\int_0^1 f_X(a-y)\,dy = \int_0^a f_X(a-y)\,dy + \int_a^1 f_X(a-y)\,dy = \int_0^a 1\,dy + \int_a^1 0\,dy$$
and the integral becomes $\int_0^a \,dy = a$

*$1<a<2$. We have a point in the interval with $y=a-1$, so we split there:
$$\int_0^1 f_X(a-y)\,dy = \int_0^{a-1} f_X(a-y)\,dy + \int_{a-1}^1 f_X(a-y)\,dy = \int_0^{a-1} 0\,dy + \int_{a-1}^1 1\,dy$$
and the integral becomes $\int_{a-1}^1 \,dy = 2-a$

*$2\le a$. For all $y\in [0,1]$, $a-y\ge 1$, so $f_X(a-y)=0$ and the integral becomes $\int_0^1 0\,dy =0$
Nothing particular to do with probability; that's just how we work with integrals of piecewise defined functions.
