title: unsigned long long to binary
body: <p>I am trying to check the set bits of an unsigned long long in c++ using below algorithm which only checks whether the bit is set or not.But my problem is the answer that I get is wrong.Please help me understand how unsigned long long is stored in binary.</p>
  
  <p>Code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;iostream&gt;
  #define CHECK_BIT(var,pos) ((var) &amp; (1&lt;&lt;(pos)))
  using namespace std;
  int main()
  {
      int pos=sizeof(unsigned long long)*8;
      unsigned long long a;
      cin&gt;&gt;a;
      pos=pos-1;
      while(pos&gt;=0)
      {
          if(CHECK_BIT(a,pos))
            cout&lt;&lt;"1";
          else
            cout&lt;&lt;"0";
          --pos;
      }
  }
  </code></pre>
  
  <p>Input :</p>
  
  <pre><code>1000000000000000000
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1010011101100100000000000000000010100111011001000000000000000000
  </code></pre>
  
  <p>Expected Output:</p>
  
  <pre><code>110111100000101101101011001110100111011001000000000000000000
  </code></pre>
  
  <p>Similarly for another input:</p>
  
  <pre><code>14141
  </code></pre>
  
  <p>Output :</p>
  
  <pre><code>0000000000000000001101110011110100000000000000000011011100111101
  </code></pre>
  
  <p>Expected Output:</p>
  
  <pre><code>11011100111101
  </code></pre>
  
  <p>In the second example(in fact for any small number) the binary pattern just repeats itself after 32 bits.</p>