dreh den alorithmus doch einfach um ?!

loop
val += input*mul; // mit 1er beginnend
mul *= 10;
continue