title: Convert uint64_t to unsigned char serialized[8]
body: <p>I am trying to convert a <code>uint64_t</code>value to a <code>unsigned char</code> array. Currently my functions are working with <code>uint32_t</code>. But as soon as I try to convert a 64bit value the results are different.</p>
  
  <p>Does somebody see a mistake?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;inttypes.h&gt;
  
  using namespace std;
  
  void serialize_uint64(const uint64_t integer, unsigned char * const serializedInteger);
  uint64_t deserialize_uint64(unsigned char * const serializedInteger);
  
  int main (int argc, char *argv[])
  {
      uint64_t test64 = 0xFF/*FFFFFFFFFFFFFF;*/;
  
      unsigned char serialized64[8];
      memset(serialized64, 0x00, sizeof(serialized64));
  
      serialize_uint64(test64, serialized64);
  
      printf("%llu = %llu\n", test64, deserialize_uint64(serialized64));
  
      return 0;
  }
  
  void serialize_uint64(const uint64_t integer, unsigned char * const serializedInteger)
  {
      serializedInteger[0] = integer &gt;&gt; 56;
      serializedInteger[1] = integer &gt;&gt; 48;
      serializedInteger[2] = integer &gt;&gt; 40;
      serializedInteger[3] = integer &gt;&gt; 32;
      serializedInteger[4] = integer &gt;&gt; 24;
      serializedInteger[5] = integer &gt;&gt; 16;
      serializedInteger[6] = integer &gt;&gt; 8;
      serializedInteger[7] = integer;
  }
  
  uint64_t deserialize_uint64(unsigned char * const serializedInteger)
  {
      uint64_t converted = 0;
  
      converted = (converted &lt;&lt; 8) | serializedInteger[0];
      converted = (converted &lt;&lt; 8) | serializedInteger[1];
      converted = (converted &lt;&lt; 8) | serializedInteger[2];
      converted = (converted &lt;&lt; 8) | serializedInteger[3];
      converted = (converted &lt;&lt; 8) | serializedInteger[4];
      converted = (converted &lt;&lt; 8) | serializedInteger[5];
      converted = (converted &lt;&lt; 8) | serializedInteger[6];
      converted = (converted &lt;&lt; 8) | serializedInteger[7];
      converted = (converted &lt;&lt; 8) | serializedInteger[8];
  
      return converted; // 4294967295
  }
  </code></pre>