title: How are u128 numbers stored in memory?
body: <p>I'm reconstructing <code>u128</code> numbers passed over the internet. My idea is to break the number down into <code>u8</code>s on one end of the connection, send those and rebuild the <code>u128</code> on the other end.</p>
  <p>I attempted reconstructing a <code>u8</code> buffer by casting its pointer to <code>*const u8</code> to <code>*const u128</code>:</p>
  <pre class="lang-rust prettyprint-override"><code>fn main() {
      let mut b = [0u8; 16];
      b[14] = 1;
      let addr = &amp;b as *const u8 as *const u128;
  
      unsafe {
          println!(&quot;{:?}&quot;, &amp;b as *const u8);
          println!(&quot;{:?}\n&quot;, b);
  
          println!(&quot;{:?}&quot;, addr);
          println!(&quot;n = {}&quot;, *addr);
      }
  }
  </code></pre>
  <p>To my surprise, the generated output looked like this:</p>
  <pre class="lang-none prettyprint-override"><code>0x7efe2088
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
  
  0x7efe2088
  n = 5192296858534827628530496329220096
  </code></pre>
  <p>I expected this array to contain</p>
  <pre class="lang-none prettyprint-override"><code>00000000 00000000 ... 00000001 00000000 = 256
  </code></pre>
  <p>Now I'm confused. Considering two different options as possibilities:</p>
  <ul>
  <li>The array is stored backwards, storing <code>b[14]</code> as the second byte;</li>
  <li>A <code>*const u128</code> (which points to <code>b[0]</code>) reads the allocated bytes backwards.</li>
  </ul>
  <p>Which one of these is correct? Is there something I don't understand about the way Rust (or computers in general) store data?</p>