title: reading binary from a file gives negative number
body: <p>Hey everyone this may turn out to be a simple stupid question, but one that has been giving me headaches for a while now. I'm reading data from a Named Binary Tag file, and the code is working except when I try to read big-endian numbers. The code that gets an integer looks like this:</p>
  
  <pre><code>long NBTTypes::getInteger(istream &amp;in, int num_bytes, bool isBigEndian)
  {
      long result = 0;
      char buff[8];
  
      //get bytes
      readData(in, buff, num_bytes, isBigEndian);
  
      //convert to integer
      cout &lt;&lt;"Converting bytes to integer..." &lt;&lt; endl;
      result = buff[0];
      cout &lt;&lt;"Result starts at " &lt;&lt; result &lt;&lt; endl;
      for(int i = 1; i &lt; num_bytes; ++i)
      {
          result = (result &lt;&lt; 8) | buff[i];
          cout &lt;&lt;"Result is now " &lt;&lt; result &lt;&lt; endl;
      }
      cout &lt;&lt;"Done." &lt;&lt; endl;
  
      return result;
  }
  </code></pre>
  
  <p>And the readData function:</p>
  
  <pre><code>void NBTTypes::readData(istream &amp;in, char *buffer, unsigned long num_bytes, bool BE)
  {
      char hold;
  
      //get data
      in.read(buffer, num_bytes);
  
      if(BE)
      {
          //convert to little-endian
          cout &lt;&lt;"Converting to a little-endian number..." &lt;&lt; endl;
          for(unsigned long i = 0; i &lt; num_bytes / 2; ++i)
          {
              hold = buffer[i];
              buffer[i] = buffer[num_bytes - i - 1];
              buffer[num_bytes - i - 1] = hold;
          }
          cout &lt;&lt;"Done." &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>This code originally worked (gave correct positive values), but now for whatever reason the values I get are either over or underflowing. What am I missing?</p>