How to evaluate the expectation of a discrete random variable?

While doing problem sets I'll usually have a problem where I'm given a density function of a random variable that can take as value either 1 or 0. This seems to be the typical definition of a discrete random variable where it can only take specific values.

I am also aware that if we have a density function than they are conditions that must be respected. For example the integral of f(x) must = 1.

However I've also overheard that when dealing with discrete random variables we don't use integrals but derivatives. I'm now very confused on what to do.

If I was told to give the expectation of a continuous random variable I would do this: $$E[x] = \int^{a}_{b} x f(x)dx$$ Where a and b are the bounds where the function is not 0 for example.

I also know that the expectation means that we do a weighted average.

I'd like to add that for a discrete random variable with a finite set of values I would have just computed the sum of each probability with the value of the random variable like this:

$$E[x] = \sum ^{i=5}_{n=1}x_{n}p_{n}$$

Can someone clear up my confusion?

Using Dirac masses: $$\delta_x(t) = \begin{cases} +\infty & \text{if x=t}\\ 0 & \text{otherwise}\end{cases}$$ with $$\int_\alpha^\beta \delta_x(t){\rm d}\! t = \begin{cases} 1 & \text{if x\in[\alpha,\beta]}\\ 0 & \text{otherwise}\end{cases}$$ which gives $$f_X(x) = f(x) + \sum_{i=1}^5 p_i\delta_{x_i}(x)$$ in such a way that $$\int_a^b f(x){\rm d}\! x + \sum_{i=1}^5 p_i = 1$$