title: when to use hton/ntoh and when to convert data myself?
body: <p>to convert a byte array from another machine which is big-endian, we can use:</p>
  
  <pre><code>long long convert(unsigned char data[]) {
    long long res;
    res = 0;
    for( int i=0;i &lt; DATA_SIZE; ++i)
      res = (res &lt;&lt; 8) + data[i];
    return res;
  }
  </code></pre>
  
  <p>if another machine is little-endian, we can use </p>
  
  <pre><code>long long convert(unsigned char data[]) {
    long long res;
    res = 0;
    for( int i=DATA_SIZE-1;i &gt;=0 ; --i)
      res = (res &lt;&lt; 8) + data[i];
    return res;
  }
  </code></pre>
  
  <p>why do we need the above functions? shouldn't we use hton at sender and ntoh when receiving? Is it because hton/nton is to convert integer while this convert() is for char array?</p>