title: Space-efficient way to encode numbers as sortable strings
body: <p>Starting with a list of integers the task is to convert each integer into a string such that the resulting list of strings will be in numeric order when sorted lexicographically.</p>
  
  <p>This is needed so that a particular system that is only capable of sorting strings will produce an output that is in numeric order.</p>
  
  <p>Example:</p>
  
  <p>Given the integers</p>
  
  <pre><code>1, 23, 3
  </code></pre>
  
  <p>we could convert the to strings like this:</p>
  
  <pre><code>"01", "23", "03"
  </code></pre>
  
  <p>so that when sorted they become:</p>
  
  <pre><code>"01", "03", "23"
  </code></pre>
  
  <p>which is correct. A wrong result would be:</p>
  
  <pre><code>"1", "23", "3"
  </code></pre>
  
  <p>because that list is sorted in "string order", not in numeric order.</p>
  
  <p>I'm looking for something <strong>more efficient</strong> than the simple zero-padding scheme. In order to cover all possible 32 bit integers we'd need to pad to 10 digits which is inefficient.</p>