title: Converting Unicode to Binary
body: <p>I am trying to convert Arabic text to <code>utf8</code> encoded bytes then to binary by using <a href="https://stackoverflow.com/questions/19255832/converting-binary-to-utf-8-in-python">this answer here</a>.</p>
  
  <p>First, I used the code as it is in the example:</p>
  
  <pre><code>'{:b}'.format(int(u'سلام'.encode('utf-8').encode('hex'), 16))
  </code></pre>
  
  <p>But I got this error:</p>
  
  <pre><code>AttributeError: 'bytes' object has no attribute 'encode'
  </code></pre>
  
  <p>Also I removed <code>.encode('hex')</code> but still gives the same error.</p>
  
  <p>Is there any way to convert <code>utf8</code> codes to binary and vise versa?</p>