title: Change byte in int - casting byte to an integer
body: <p>I'm streaming data from the server. Server sends various BigEndian variables, but also sends bytes (representing number). One of my <code>SocketClient.read</code> overloads accepts <code>(int length, char* array)</code>. I want to <strong>pass an integer variable pointer</strong> to this function to <strong>get 0-255 value</strong> in it (unsigned byte).</p>
  <h3>What have I tried:</h3>
  <pre><code>unsigned int UNSIGNED_BYTE;
  socket.read(1, &amp;((char*)&amp;UNSIGNED_BYTE)[0]);  //I am changing 1st byte of a variable - C++ uses little endian
  //I know that function reads 6, and that is what I find in 1st byte
  std::cout&lt;&lt;(int)((char*)&amp;UNSIGNED_BYTE)[0]&lt;&lt;&quot;)\n&quot;;  //6   - correct
  std::cout&lt;&lt;UNSIGNED_BYTE&lt;&lt;&quot;)\n&quot;;  //3435973638   -What the hell?
  </code></pre>
  <p>According to the above, I am changing the <strong>wrong part of the <code>int</code></strong>. But <strong>what else should I change</strong>?</p>
  <h3>My class declaration and implementation:</h3>
  <pre><code>/*Declares:*/
  bool read(int bytes, char *text);
  /*Implements:*/
  bool SocketClient::read(int bytes, char *text) {
        //boost::system::error_code error;
        char buffer = 0;
        int length = 0;
        while(bytes&gt;0) {
          try
          {
            size_t len = sock.receive(boost::asio::buffer(&amp;buffer, 1));  //Read a byte to a buffer
          }
          catch(const boost::system::system_error&amp; ex) {
              std::cout&lt;&lt;&quot;Socket exception: &quot;&lt;&lt;ex.code()&lt;&lt;'\n';
              return false;   //Happens when peer disconnects for example
          }
          if(byteEcho)
              std::cout&lt;&lt;(int)(unsigned char)buffer&lt;&lt;' ';
          bytes--;      //Decrease ammount to read
          text[length] = buffer;
          length++;
          
        }
        return true;
  }
  </code></pre>