How do I append an integer to the left of another integer?

91 Views Asked by At

For example:

. is my append operator

f(x,y)    = |x| . |y|
f(1,45)   = 145
f(233,10) = 23310
f(8,2)    = 82
f(0,1)    = 1

This is a trivially easy problem to solve in programming using string concatenation. However, I can't seem to think of a good way to do this using purely arithmetic operations.

2

There are 2 best solutions below

0
On

$f(x,y)=x\cdot10^{\lfloor\log_{10}y\rfloor+1}+y$

0
On
  1. Take $log_{10}(b)$ and round down to find the number of digits $n$.
  2. multiply $a$ by $10^n$
  3. add $b$