title: How to convert a word in string to binary
body: <p>I was working on a module(the <code>import module</code> stuff) which would help to convert words in string to <code>hex</code> and <code>binary</code>(And octal if possible).I finished the hex part.But now I am struggling in case of the binary.I don't know where to start from or what to do.What I want to do is simple.It would take an input string such as <code>'test'</code>.The function inside the module would convert it to binary.</p>
  
  <p>What I have done till now is given below:</p>
  
  <pre><code>def string_hex(string): # Converts a word to hex
      keyword = string.encode()
      import binascii
      hexadecimal=str(binascii.hexlify(keyword), 'ascii')
      formatted_hex=':'.join(hexadecimal[i:i+2] for i in range(0, len(hexadecimal), 2))
      return formatted_hex
  
  def hex_string(hexa):
  # hexa(Given this name because there is a built-in function hex()) should be written as string.For accuracy on words avoid symbols(, . !)
      string = bytes.fromhex(hexa)
      formatted_string = string.decode()
      return formatted_string
  </code></pre>
  
  <p>I saved in the directory where I have installed my python in the name <code>experiment.py</code>.This is the way I call it.</p>
  
  <pre><code>&gt;&gt;&gt; from experiment import string_hex
  &gt;&gt;&gt; string_hex('test')
  '74:65:73:74'
  </code></pre>
  
  <p>Just like that I am able to convert it back also like this:</p>
  
  <pre><code>&gt;&gt;&gt; from experiment import hex_string
  &gt;&gt;&gt; hex_string('74657374')
  'test'
  </code></pre>
  
  <p>Just like this wanted to convert words in strings to binary.And one more thing I am using <code>python 3.4.2</code>.Please help me.</p>