Question on 1-1 & onto function While I was studying relations & functions I came across with this question which I can't figure out the meaning of it. Please help.
Let $X$ be the set of all strings of finite length consisting of $0$'s and $1$'s. The function $h:X\to\mathbb{Z}_{\geq 0}$ (non-negative integers) is defined by $h(x)=n-\bar{x}$ where $n$ is the length of $x$ and $\bar{x}$ is the number of $1$'s in $x$.
How shall I determine whether $h$ is one-one and onto?
 A: We explain what the function $h$ does. After that you will not find the problem hard. 
Let $x$ be the string $011000$. This string has length $6$, and has $2$ $1$'s. So $h(x)=6-2=4$. Let $x$ be the string $0000000$. This has length $7$, and no $1$'s, so $h(x)=7-0=7$. Strings of any length are allowed. With a bit of patience, you can find $h(x)$ where $x=11110010010100101001010010101001010100111100000$. 
Note that all values of $h(x)$ are non-negative integers, since the length of a string cannot be less than the number of $1$'s in the string. 
Now that you know what $h(x)$ does, it should not be hard to come up with two specific distinct strings $x$ and $y$ such that $h(x)=h(y)$. When you have done that, you  will have shown that the function $h$ is not one to one. 
Now that you know what $h$ does, it should also not be hard to show that $h$ is onto. For concreteness, first think of how to make a string $x$ such that $h(x)=17$.
Remark: Your responses can become nearly instantaneous if you think about the following question: If we take the length of a string, and subtract the number of $1$'s, what do we get?
