title: Manipulations with bits
body: <p>I have binary file that is represented in hexa e.g</p>
  
  <pre><code> 4d42 b666 000a 0000 0000 0036 0000 0028
  </code></pre>
  
  <p>The first 4 bytes represent value which i want to extract.</p>
  
  <p>I know i can extract it right</p>
  
  <pre><code>std::ifstream is("img.bmp", std::ifstream::binary);
  uint64_t data = 0;
  is.read((char*)&amp;data,4)
  </code></pre>
  
  <p>which would result in <code>3060157762</code></p>
  
  <p>However using </p>
  
  <pre><code>  unsigned char * test   = new unsigned char [ 4  ]; 
    is.read((char*)test , 4 );
    uint64_t t = 0;
    for( int i = 0; i &lt; 4;i++){
      t &lt;&lt;= 8; // 2 hexa symbols = 1 byte = 1 char = 8 bits
      t|= test[i];
    }
    cout &lt;&lt; t &lt;&lt; endl;
  </code></pre>
  
  <p>this results in <code>1112368822</code> which obviously differ.</p>
  
  <p>I wonder how could we achieve same result with second method? What are some bitwise tricks for this? I cannot think of anything besides the method i have shown.</p>
  
  <p>Thanks for help.</p>