title: How to get the 8 high bits of a 16-bit variable?
body: <p>I'm doing some AVR programming and am kinda getting to grips with this whole bit operation thing but still ain't so sure about data type conversion.</p>
  
  <p>For example:</p>
  
  <p>I have a 16-bit variable (<code>myValue</code>) that corresponds the state of 16 LEDs over 2 ports (e.g. 8 LEDs on Port A and 8 on Port D). The 8 high bits of <code>myValue</code> are on Port D.</p>
  
  <p>So my idea was to essentially use <code>(0b0000000011111111 &amp; myValue)</code> to get the values for Port A and <code>(0b1111111100000000 &amp; myValue)</code> for Port D</p>
  
  <p>The question is then can I then do something like <code>uint8_t portA = (0b0000000011111111 &amp; myValue)</code>? I believe I can just simply then set</p>
  
  <pre><code>PORTA |= portA
  </code></pre>
  
  <p>since Port A has only 8 pins (in my case).</p>
  
  <p>The problem arises in Port D since using unsigned 8 bit on the other hand is not possible for Port D because it will still remain a 16-bit variable after the <code>&amp;</code> operation? How do I then set an 8-pin Port D with a 16-bit variable?</p>