title: Why doesn't my bit left shift?
body: <p>I'm using embedded C on Keil. I'm trying to program such that it stores a bit, bit shifts and then it stores it again and it repeats until all eight bits are stored.</p>
  
  <p>However, when I debug (maybe debug wrongly), the value only shows "01 00 00 00 00 00 00...". When it stores logic'1' and then when it shift left, it shows "02 00 00 00 00 00 00...". When the loop repeats, it shows the same thing over and over again. What I expected was "01 01 01 01 01 01 01..." (Let's say all the input bits was '1').  How do I solve this problem?</p>
  
  <pre><code>#include &lt;reg51.h&gt;
  
  sbit Tsignal = P1^2;
  unsigned char xdata x[500];
  
  for(u=0; u&lt;8; u++)
  {
       x[i] = x[i] &lt;&lt; 1;
       x[i] = Tsignal;  //Store Tsignal in x
  }
  </code></pre>
  
  <p>Ah, I have solved it already.</p>
  
  <pre><code>unsigned int u;
  unsigned char p;
  unsigned char xdata x[500];
  
  for(u=0; u&lt;8; u++)    //Bit Shift Loop
  {
      x[i] = x[i] &lt;&lt;1;   //Left Bit Shift by 1
      p = Tsignal;       //Store Tsignal to Buffer p
      x[i] |= p;
  } //End Bitshift loop
  </code></pre>