title: Convert a two byte UInt8 array to a UInt16 in Swift
body: <p>With Swift I want to convert bytes from a uint8_t array to an integer.</p>
  
  <p>"C" Example:</p>
  
  <pre><code>char bytes[2] = {0x01, 0x02};
  NSData *data = [NSData dataWithBytes:bytes length:2];
  NSLog(@"data: %@", data); // data: &lt;0102&gt;
  
  uint16_t value2 = *(uint16_t *)data.bytes;
  NSLog(@"value2: %i", value2); // value2: 513
  </code></pre>
  
  <p>Swift Attempt:</p>
  
  <pre><code>let bytes:[UInt8] = [0x01, 0x02]
  println("bytes: \(bytes)") // bytes: [1, 2]
  let data = NSData(bytes: bytes, length: 2)
  println("data: \(data)") // data: &lt;0102&gt;
  
  let integer1 = *data.bytes // This fails
  let integer2 = *data.bytes as UInt16 // This fails
  
  let dataBytePointer = UnsafePointer&lt;UInt16&gt;(data.bytes)
  let integer3 = dataBytePointer as UInt16 // This fails
  let integer4 = *dataBytePointer as UInt16 // This fails
  let integer5 = *dataBytePointer // This fails
  </code></pre>
  
  <p>What is the correct syntax or code to create a UInt16 value from a UInt8 array in Swift?</p>
  
  <p>I am interested in the NSData version and am looking for a solution that does not use a temp array.   </p>