merge the critical part of itoa and xtoa