Why does bytes.fromhex() treat some hex values strangely?
<p>I'm trying to use the socket library in Python to send bytes of two hex digits to a piece of hardware programmed to accept them.  To create the bytes from a user-entered string of hex digits, I'm trying to use <code>bytes.fromhex()</code> method described <a href="https://docs.python.org/dev/library/stdtypes.html#bytes.fromhex" rel="nofollow noreferrer">here</a>.</p>
<p>Why does the following:</p>
<pre><code>hexstring = &quot;bb 0D 02 55 55 5A ce&quot;
data = bytes.fromhex(hexstring)
print(data)
</code></pre>
<p>give me:</p>
<pre><code>b'\xbb\r\x02UUZ\xce'
</code></pre>
<p>instead of:</p>
<pre><code>b'\xbb\x0d\x02\x55\x55\x5a\xce'
</code></pre>
<p>?</p>
<p>And how do I get it to produce the second output? I'm using Python 3.5.</p>