title: Using bitwise operators in C++ to change 4 chars to int
body: <p>What I must do is open a file in binary mode that contains stored data that is intended to be interpreted as integers.  I have seen other examples such as <a href="https://stackoverflow.com/questions/544928/reading-integer-size-bytes-from-a-char-array">Stackoverflow-Reading “integer” size bytes from a char* array.</a> but I want to try taking a different approach (I may just be stubborn, or stupid :/). I first created a simple binary file in a hex editor that reads as follows.  </p>
  
  <p><code>00 00 00 47 00 00 00 17 00 00 00 41</code><br>
  This (should) equal 71, 23, and 65 if the 12 bytes were divided into 3 integers.</p>
  
  <p>After opening this file in binary mode and reading 4 bytes into an array of chars, how can I use bitwise operations to make char[0] bits be the first 8 bits of an int and so on until the bits of each char are part of the int. </p>
  
  <pre><code> 
  My integer = 00        00        00        00  
   +           ^         ^         ^         ^
  Chars      Char[0]  Char[1]   Char[2]   Char[3]
               00        00        00        47
  
  
  So my integer(hex) = 00 00 00 47 = numerical value of 71
  </code></pre>
  
  <p>Also, I don't know how the endianness of my system comes into play here, so is there anything that I need to keep in mind?</p>
  
  <p>Here is a code snippet of what I have so far, I just don't know the next steps to take. </p>
  
  <pre><code>
  std::fstream myfile;
      myfile.open("C:\\Users\\Jacob\\Desktop\\hextest.txt", std::ios::in | std::ios::out | std::ios::binary);
      if(myfile.is_open() == false)
      {
          std::cout &lt&lt "Error" &lt&lt std::endl;
      }
      char* mychar;
      std::cout &lt&lt myfile.is_open() &lt&lt std::endl;
      mychar = new char[4];
      myfile.read(mychar, 4);
  </code></pre>  
  
  <p>I eventually plan on dealing with reading floats from a file and maybe a custom data type eventually, but first I just need to get more familiar with using bitwise operations.
  Thanks.</p>