title: is there a way to convert an integer to be always a 4 digit hex number using Lua
body: <p>I'm creating a Lua script which will calculate a temperature value then format this value as a 4 digit hex number which must always be 4 digits. Having the answer as a string is fine.</p>
  
  <p>Previously in C I have been able to use</p>
  
  <pre><code>data_hex=string.format('%h04x', -21)
  </code></pre>
  
  <p>which would return ffeb</p>
  
  <p>however the 'h' string formatter is not available to me in Lua
  dropping the 'h' doesn't cater for negative answers i.e</p>
  
  <pre><code>data_hex=string.format('%04x', -21)
  
  print(data_hex)
  </code></pre>
  
  <p>which returns ffffffeb</p>
  
  <pre><code>data_hex=string.format('%04x', 21)
  
  print(data_hex)
  </code></pre>
  
  <p>which returns 0015</p>
  
  <p>Is there a convenient and portable equivalent to the 'h' string formatter?</p>