title: Bitwise Operations in a Steganography Program (C)
body: <p>I'm relatively new to both C and bitwise operations and I'm having trouble with an assignment I've been given in my class. A majority of the code has been given to me, but I've been having issues figuring out a part pertaining to bitwise operations. Once I figure this part out, I'll be golden. I hope that someone can help!</p>
  
  <p>Here is the excerpt from my assignment:</p>
  
  <blockquote>
    <blockquote>
      <p>You will need to use 8 bytes of an image to hide one byte of information (remember that only LSBs of the cover image can be modified). You will use the rest of the 16 bytes of the cover image to embed 16 bits of b.size (two least significant bytes of the size field for the binary data), next 32 bytes of the cover will be used to embed the file extension
      for the payload file, and after that you will use 8*b.size bytes to embed the payload (b.data).</p>
    </blockquote>
  </blockquote>
  
  <p>What this program is doing is stenography of an image, and I have to modify the least significant bits of the image read in using data from a file that I created. Like I said, all of the code for that is already written. I just can't figure out how to modify the LSBs. Any help would be greatly appreciated!!!</p>
  
  <p>The functions I have to use for reformatting the LSBs are as follows:</p>
  
  <pre><code>byte getlsbs(byte *b);
  void setlsbs(byte *b, byte b0);
  </code></pre>
  
  <p>This is what I've attempted thus far:</p>
  
  <pre><code>/* In main function */
  b0 = getlsbs(&amp;img.gray[0])
  
  /* Passing arguments */
  byte getlsbs(byte *b)
  {
      byte b0;
      b0[0] = b &gt;&gt; 8;
      return b0;
  }
  </code></pre>
  
  <p>I'm honestly at a complete loss. I've been working on this all night and I still barely have made headway. </p>