title: How do I convert two u8 primitives into a u16 primitive?
body: <p>I'm reading a binary file into a Rust program using a <code>Vec&lt;u8&gt;</code> as a buffer. Two bytes in the stream represent a big-endian <code>u16</code>.</p>
  
  <p>So far, the only way I've figured out how to convert to a primitive <code>u16</code> involves converting the two elements to <code>String</code>s first, and it looks <em>terrible</em>.</p>
  
  <p>Code:</p>
  
  <pre><code>let vector: Vec&lt;u8&gt; = [1, 16].to_vec();
  let vector0: String = format!("{:02x}", vector[0]);
  let vector1: String = format!("{:02x}", vector[1]);
  let mut vector_combined = String::new();
  vector_combined = vector_combined + &amp;vector0.clone();
  vector_combined = vector_combined + &amp;vector1.clone();
  let number: u16 = u16::from_str_radix(&amp;vector_combined.to_string(), 16).unwrap();
  
  println!("vector[0]: 0x{:02x}", vector[0]);
  println!("vector[1]: 0x{:02x}", vector[1]);
  println!("number: 0x{:04x}", number);
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>vector[0]: 0x01
  vector[1]: 0x10
  number: 0x0110
  </code></pre>