I'm studying for statistics, and I realized two ways to represent expectancy of probability distribution that I gave above.
The problem is I don't understand how they can be same. One is x, which doesn't have to be between 1 and zero. But the other is p(x), which has to be between 1 and zero. How those two can give the same result?
I think you're confusing notation so let me get the notation straight and it should clarify the definition of expectation. Also check wikipedia: expectation, Law of the unconscious statistician
The definition of expectation $\mathbb{E}(X)$ for continuous random variable $X$ with density $p(x):\mathbb{R} \to \mathbb{R}$ is:
$$ \mathbb{E}(X):= \int_{-\infty}^{\infty} x p(x)dx. \tag{*} $$
Now, suppose you have a new random variable $Y$ given by $$Y:= f(X), $$ for some function $f:\mathbb{R} \to \mathbb{R}$. There is the law of unconscious statistician which says that the expectation of $Y$ is equal to
$$ \mathbb{E}[Y] \equiv \mathbb{E}[f(X)] = \int_{-\infty}^{\infty} f(x) p(x)dx. $$ This is a nice law, because it tells you, that you can forgo finding the density of $Y$ in order to compute its expectation directly according to $(*)$. Instead you can just "reuse" the density of $X$, while you substitute $x \Leftrightarrow f(x)$.