title: Mysql Bitwise operations and filter
body: <p>I try to implement a bitwise filter using MYSQL (with udf if needed)</p>
  
  <p>The filter is something like a AND but I want to use the mask to build a new bit string...
  Let me explain you with a sample :</p>
  
  <p>Suppose I have a table with blob storing 8 bit streams:</p>
  
  <ul>
  <li>data1: 10110110</li>
  <li>data2: 01100010</li>
  <li>data3: 00010011</li>
  </ul>
  
  <p>Then I have a mask to apply to get the bits from data when mask value is 1</p>
  
  <ul>
  <li>MASK:  00101011</li>
  </ul>
  
  <p>And so get the following expected results:</p>
  
  <ul>
  <li>data1: 1010</li>
  <li>data2: 1010</li>
  <li>data3: 0011</li>
  </ul>
  
  <p>Is there a way to optimize the filtering, without looping on each bit of "mask" to get the corresponding value in "data" row...</p>
  
  <p><strong>CLARIFICATION</strong></p>
  
  <p>I've just taken 8 bits for the post, but it's more like 256 bytes</p>
  
  <p>for Joe : To clarify the exemple, the mask 00101011 is interpreted as : get the bit value from data field at position 3,5,7,8, if you read the mask from left to right, enumerated from bit 1 to bit 8... Hope this clarification is "clear"...</p>