title: Escape problem with hex
body: <p>I need to print escaped characters to a binary file using Ruby. The main problem is that slashes need the whole byte to escape correctly, and I don't know/can't create the byte in such a way.</p>
  
  <p>I am creating the hex value with, basically:</p>
  
  <pre><code>'\x' + char
  </code></pre>
  
  <p>Where char is some 'hex' value, such as 65. In hex, \x65 is the ASCII character 'e'.</p>
  
  <p>Unfortunately, when I puts this sequence to the file, I end up with this:</p>
  
  <pre><code>\\x65
  </code></pre>
  
  <p>How do I create a hex string with the properly escaped value? I have tried a <strong><em>lot</em></strong> of things, involving single or double quotes, pack, unpack, multiple slashes, etc. I have tried so many different combinations that I feel as though I understand the problem less now then I did when I started.</p>
  
  <p>How?</p>