title: Converting 2 bytes to Short in C#
body: <p>I'm trying to convert two bytes into an unsigned short so I can retrieve the actual server port value. I'm basing it off from this <a href="http://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol" rel="noreferrer">protocol specification</a> under Reply Format. I tried using <a href="https://msdn.microsoft.com/en-us/library/system.bitconverter.touint16(v=vs.110).aspx" rel="noreferrer">BitConverter.ToUint16()</a> for this, but the problem is, it doesn't seem to throw the expected value. See below for a sample implementation:</p>
  
  <pre><code>int bytesRead = 0;
  
  while (bytesRead &lt; ms.Length)
  {
      int first = ms.ReadByte() &amp; 0xFF;
      int second = ms.ReadByte() &amp; 0xFF;
      int third = ms.ReadByte() &amp; 0xFF;
      int fourth = ms.ReadByte() &amp; 0xFF;
      int port1 = ms.ReadByte();
      int port2 = ms.ReadByte();
      int actualPort = BitConverter.ToUInt16(new byte[2] {(byte)port1 , (byte)port2 }, 0);
      string ip = String.Format("{0}.{1}.{2}.{3}:{4}-{5} = {6}", first, second, third, fourth, port1, port2, actualPort);
      Debug.WriteLine(ip);
      bytesRead += 6;
  }
  </code></pre>
  
  <p>Given one sample data, let's say for the two byte values, I have 105 &amp; 135, the expected port value after conversion should be 27015, but instead I get a value of 34665 using BitConverter.</p>
  
  <p>Am I doing it the wrong way?</p>