title: Difference between different hex types/representations in Python
body: <p>Working my way through some some Python code, I'm noticing there are a number of different representations for hexadecimal values. For example, if I choose a number like so:</p>
  
  <pre><code>xx = '\x03\xff'
  </code></pre>
  
  <p>Then the following command (a version of which I'm using to convert little endian to big endian)</p>
  
  <pre><code>yy = hex(struct.unpack('&gt;H', xx)[0])
  </code></pre>
  
  <p>will return:</p>
  
  <pre><code>'0x3ff'
  </code></pre>
  
  <p>However, this command</p>
  
  <pre><code>zz = xx.encode('hex')
  </code></pre>
  
  <p>will return:</p>
  
  <pre><code>'03ff'
  </code></pre>
  
  <p>Finally, printing just the value out will return this</p>
  
  <pre><code>'\x03\xff'
  </code></pre>
  
  <p>From the looks of it there are three different types of hex then. </p>
  
  <ol>
  <li><code>'\xFF'</code></li>
  <li><code>'0xFF'</code></li>
  <li><code>'FF'</code></li>
  </ol>
  
  <p><strong>What's the difference?</strong></p>
  
  <p><strong><em>Bonus points</em></strong> if someone could suggest a better way of converting a little endian to a big endian number. The above method for <code>yy</code> won't work for numbers larger than two bytes obstinately enough and I'm working with some hex strings that are 16 bytes long  (including values that don't correspond to an ascii/integer value)</p>