What is the concept of ordinal utility? I have read in many books that since utility cannot be measured - so ordinal concept or comparison concept is used. 
If that is so, how can one define a mathematical function for utility which gives a cardinal value for inputs.
The two things mentioned above are inconsistent with each other.

Can somebody explain what I am missing here.
Suppose Alex, Bryan, and Chris run in a race. Alex is the fastest and Chris is the slowest. So far I have only given you ordinal information about where they finished.

I guess you'd be okay with me taking that ordinal information and saying "Alex finished first, Bryan finished second, and Chris finished third". But then I just defined a function that assigns a number to each of the ordinal places:
$$f(x)=\begin{cases}1\text{ if }x=\text{Alex}\\2\text{ if }x=\text{Bryan}\\3\text{ if }x=\text{Chris}.\end{cases}$$
Note that the numbers 1, 2, 3 don't tell us how much faster Alex was than Bryan, only that he was somewhat faster.

Utility functions are just like this: they give bigger numbers to the best alternatives. But the size of those numbers don't tell us how much better the best alternative is, only that it is better. That is the sense in which the function is ordinal.