title: Set Least Significant Bit in C
body: <p>I write a simple steganography tool in C with bmp images.</p>
  
  <p>I read the image to memory and the text to hide in char bytes[8] one character at a time.</p>
  
  <p>so eg. </p>
  
  <pre><code>a=0d97
  bytes[0] = 0
  bytes[1] = 1
  bytes[2] = 1
  bytes[3] = 0
  bytes[4] = 0
  bytes[5] = 0
  bytes[6] = 0
  bytes[7] = 1
  </code></pre>
  
  <p>Then i 'll go to the first image byte(<code>char *ptr points</code> it every time) to put the bytes[0] to LSB, then the next one etc.</p>
  
  <p>If the <code>*ptr=0xff or 0b11111111</code> i have to set the last 1 to 0. This can be with     </p>
  
  <pre><code>*ptr = *ptr ^ 0x01 ;
  </code></pre>
  
  <p>but if the <code>*ptr = 0x00</code> or <code>0b00000000</code> the xor doesent work because <code>0^1=1</code></p>
  
  <p>I 'm confused how to set the case. I need a operator to make the last bit every time 0 and not touch the others in case LSB is 1 or 0.</p>