Python 3.2+ converting int to bytes
<p>I'm having a problem converting int to bytes in Python.  </p>

<p>This works - </p>

<pre><code>&gt;&gt;&gt; (1024).to_bytes(2, 'big')
b'\x04\x00'  
</code></pre>

<p>However this does not work as I would expect - </p>

<pre><code>&gt;&gt;&gt; (33).to_bytes(2, 'big')
b'\x00!'
</code></pre>

<p>What am I not understanding?</p>

<p><code>!</code> has the decimal value 33 by ascii standarts, so that python-shell can show it without escape codes, and so it does.</p>

<pre><code>&gt;&gt;&gt; x = b'\x00\x21'
&gt;&gt;&gt; x
b'\x00!'
</code></pre>

python python-3.2