title: Testing whether specific bits are set in a DWORD flag
body: <p><strong>I have a DWORD variable &amp; I want to test if specific bits are set in it.</strong> I have my code below but I am not sure if I am transferring the bits from the win32 data type KBDLLHOOKSTRUCT to my lparam datatype correctly?</p>
  
  <p>See MSDN that documents the DWORD flag variable: <a href="http://msdn.microsoft.com/en-us/library/ms644967(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms644967(v=vs.85).aspx</a></p>
  
  <pre><code>union KeyState 
  {
      LPARAM lparam;      
  
      struct     
      {         
          unsigned nRepeatCount : 16;         
          unsigned nScanCode    : 8;         
          unsigned nExtended    : 1;         
          unsigned nReserved    : 4;         
          unsigned nContext     : 1;         
          unsigned nPrev        : 1;         
          unsigned nTrans       : 1;     
      }; 
  }; 
  
  
  KBDLLHOOKSTRUCT keyInfo = *((KBDLLHOOKSTRUCT*)lParam);
  KeyState myParam;
  myParam.nRepeatCount    = 1;
  myParam.nScanCode       = keyInfo.scanCode;
  myParam.nExtended       = keyInfo.flags &amp;&amp; LLKHF_EXTENDED; // maybe it should be keyInfo.flags &amp; LLKHF_EXTENDED or keyInfo.flags &gt;&gt; LLKHF_EXTENDED
  myParam.nReserved       = 0;        
  myParam.nContext        = keyInfo.flags &amp;&amp; LLKHF_ALTDOWN;     
  myParam.nPrev           = 0; // can store the last key pressed as virtual key/code, then check against this one, if its the same then set this to 1 else do 0   
  myParam.nTrans          = keyInfo.flags &amp;&amp; LLKHF_UP;
  
  
  // Or maybe I shd do this to transfer bits...
  myParam.nRepeatCount    = 1;
  myParam.nScanCode       = keyInfo.scanCode;
  myParam.nExtended       = keyInfo.flags &amp; 0x01;
  myParam.nReserved       = (keyInfo.flags &gt;&gt; 0x01) &amp; (1&lt;&lt;3)-1;      
  myParam.nContext        = keyInfo.flags &amp; 0x05;     
  myParam.nPrev           = 0;       // can store the last key pressed as virtual key/code, then check against this one, if its the same then set this to 1 else do 0   
  myParam.nTrans          = keyInfo.flags &amp; 0x07;
  </code></pre>