Convert a Pair of Integers to a Integer, Optimally? 
What's the best algorithm that takes in two positive integers $a,b$
  and returns a positive integer $c$, such that all $c$'s are unique and
  $(a,b)$ is distinguishable from $(b,a)$; where the best means that the
  length of $c$ in terms of digits is shortest possible, on average?
This implies that we can work out $a,b$ from $c$ with the same algorithm. (reversing it)

If we have a bound $x$ such that $a,b\le x$, then $f(a,b)$ has $x^2$ unique values which means our $c$ needs to take values from $[1,x^2]$ to have the least amount of digits, which can be achieved with the following function:
$$f(a,b)=(a-1)x+b$$
If $x$ does not exist, what's the optimal algorithm then? 
(To make sense which algorithm is the shortest, I was comparing the length of the $c$ with the sum of lengths of $a,b$ and calculating the average which is more precise the more values we consider.)

I had two ideas so far;

$(1)$ Factorization
Take the factors of $a$ and $b$. Now you can use the second longest sequence of $0$s as a separator between factors, and the longest sequence of $0$s as a separator between the factors of the two numbers. 
Example: $f(123,1007)=(3\times41 ),( 19\times53)=30410019053$
Example: $f(30,1006)=(2\times3\times5),(2\times503)=2003005000200503$
But this can be optimized, for cases such as $f(2^{64},3^{64})$, and even then, seems like it is too much extra digits.

$(2)$ Trailing zeroes
Take $a$, reverse its digits and put a random digit in front of the first digit. That way, the result does not have trailing zeroes. Then use the longest sequence of $0$s as a separator from $b$. 
Example: $f(123,456)=93210456$
Example: $f(123,10100)=932100010100$
Example: $f(420,314)=902400314$
This also has room for optimization if we look at individual cases and add more specific rules. But it feels like it won't be optimal even then.
 I suppose the optimal solution would need to look at couple or more cases individually?

Here's something that should do the trick:  Given $a$ and $b$, let $h$ be the number of digits in $a$, $k$ be the number of digits in $b$, and $n=h+k$ the total number of digits. First write down $n$, then $h$, then $n$ $0$'s, then $k$, then $a$, then $b$.  For example
$$f(13,47)=42000021347\quad\text{while}\quad f(134,7)=43000011347$$
To get from $c$ back to $(a,b)$, count the number of digits in $c$, then peel off the largest number from the beginning that's less than that.  E.g., from the $11$-digit number $42000021347$, you get $4$, not $42$.  That tells you the concatenatation is $ab=1347$, leaving $200002$ to be the concatenation of the number of digits in $a$ and $b$ individually, with $4$ $0$'s in between.
You can probably get by with fewer than $n$ $0$'s.  My first attempt didn't have any at all, e.g., $g(13,47)=4221347$, but then I realized you can run into ambiguities, such as
$$g(12345678910,1)=g(1,23456789101)=12111123456789101)$$
where it's not clear if $12=11+1$ or $1+11$.
