title: Bitwise Operations on char*
body: <p>GCC gives error when compiling the code below. The commented two lines instead of the other <strong>or</strong> and <strong>shift</strong> lines work, but I'm not sure if the castings are necessary and true.</p>
  
  <p>The error is this: <em>invalid operands to binary | (have 'char*' and 'int')</em></p>
  
  <p>Thanks.</p>
  
  <pre><code>void bits2byte(int *bits, char *byte) {
      byte = 0;
      int i;
      for (i = 0; i&lt;8; i++) {
          if (bits[i] == 1) {
              byte = byte | 0x01;
              // byte = (char*)((int)byte | 0x01);
          }
          if (i&lt;7) {
              byte = byte &lt;&lt; 0x01;
              // byte = (char*)((int)byte &lt;&lt; 0x01);
          }
      }
  }
  int main() {
      int input_bits[] = {1, 1, 0, 1, 0, 0, 1, 1};
      char output_byte;
      bits2byte(input_bits, &amp;output_byte);
  }
  </code></pre>
  
  <p><strong>Edit:</strong> I understand that this is a pass-by-reference problem. I'm trying to modify the byte. I want the function to convert bits into a byte. Actually I've first written it in the way all the answerers/commenters suggest, but the pass by reference example in <a href="http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr233.htm" rel="nofollow">http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr233.htm</a> confused my mind.</p>