title: How can I convert a character-encoded binary string to hexadecimal in SQL Server?
body: <p>I'm trying to take a <code>VARCHAR(MAX)</code> with data in it as follows:
  "00001001010001010111010101..." etc.</p>
  
  <p>Then encode it as hexadecimal for more efficient return to the client.</p>
  
  <p>Is it possible to do this? Either directly or converting the string into a real binary column first before calling <code>master.dbo.fn_varbintohexstr</code>?</p>
  
  <p>As an example, given the string:</p>
  
  <pre><code>0000100101000101011101011110
  </code></pre>
  
  <p>We should end up with:</p>
  
  <pre><code>0000 = 0
  1001 = 9
  0100 = 4
  0101 = 5
  0111 = 7
  0101 = 5
  1110 = E
  </code></pre>
  
  <p>094575E.</p>
  
  <p>Or if there is an even more efficient method (reading binary directly?) then that would be even better. SQL Server 2000 compatible solutions are preferable.</p>