Skip to content

Instantly share code, notes, and snippets.

@key
Created November 24, 2015 09:51
Show Gist options
  • Save key/ca2b49b2f53448fdef91 to your computer and use it in GitHub Desktop.
Save key/ca2b49b2f53448fdef91 to your computer and use it in GitHub Desktop.
Convert `Byte Array` to `UInt8` in Swift
// bytes
var buffer: [UInt8] = [0b11111111, 0b11111100, 0b0101, 0b00001]
// get part of bytes
var data = NSData(bytes: [UInt8(buffer[0])], length: sizeof(UInt8))
var target: UInt8 = 0
data.getBytes(&target, length: sizeofValue(data))
print(target) // 255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment