title: Could someone explain the difference between & and &&?
body: <p>1st Semester Student here. I'm confused about the differences between the bitand (&amp;) and the logical and (&amp;&amp;), and the same with the bitor (|), the logical or (||), and the Xor (^).  Specifically, I've a bit of code that I thought required the || or &amp;&amp; to function, but.. apparently not?  Here's the code in question:</p>
  
  <pre><code>cout &lt;&lt; "Please enter your biological sex (M or F): " &lt;&lt; endl;
  cin &gt;&gt; sex;
  
  //Repetition Structure
  while (toupper(sex) != 'M' &amp;&amp; 'F')
  {
      cout &lt;&lt; "Invalid entry. Please enter your biological sex (M or F): " &lt;&lt; endl;
      cin &gt;&gt; sex;
  } //end while
  </code></pre>
  
  <p>I tried using || at first, but it gave me the "invalid entry" reply no matter how I answered it.  I looked around on the forums, found that &amp;&amp; would be better and tried using it.  It worked - at first.  Then, for no apparent reason, it stopped taking 'F' as an answer (the code wasn't changed).</p>
  
  <p>To correct this, I tried using Xor (^) which failed, and then bitand (&amp;, instead of &amp;&amp;), which apparently made it function correctly once more.  But, I've seen warnings that you can still get the right answers using either &amp; or &amp;&amp;, but one does not equal the other and could cause problems later.  This is why I need clarification (also, it's just good stuff to know).</p>
  
  <p>UPDATE:  Since this was tagged as a duplicate, I'll clarify my intent:  I want to know more about &amp; and &amp;&amp;, why you use one and not the other, as well as the same info for ^, | and ||.  The tagged thread has examples of using one versus another, but they don't explain the details of the operations themselves.  As I'm struggling with understanding the very nature of the operations themselves, those explanations are crucial; examples alone won't clarify my understanding.</p>