title: Replace least significant bit with bitwise operations
body: <p>What is a optimal way to replace the Least Significant Bit of a byte, with a provided bit?</p>
  
  <p>I know how to do checking and comparing last bit (using for example posix ffs() function), but I want to know if there are solutions with better performance, without checking if replacing bit is 0 or 1. </p>
  
  <p>The example is written in python as pseudocode, but I will implement the working algorithm in C:</p>
  
  <pre><code>&gt;&gt;&gt; bin(0b1)             # bit is  '0b1'
  &gt;&gt;&gt; bin(128)             # byte is '0b10000000'
  &gt;&gt;&gt; bin(129)             # byte is '0b10000001'
  
  &gt;&gt;&gt; bin(128 OPERATOR 0b1)       # Replace LSB with 1
  '0b10000001'
  &gt;&gt;&gt; bin(128 OPERATOR 0b0)       # Keep LSB at 0
  '0b10000000'
  
  &gt;&gt;&gt; bin(129 OPERATOR 0b1)       # Keep LSB at 1
  '0b10000001'
  &gt;&gt;&gt; bin(129 OPERATOR 0b0)       # Replace LSB with 0
  '0b10000000'
  </code></pre>
  
  <p>Obviously operator can be a set of operations, but I'm looking for the optimal (fastest) method.</p>