Created
November 24, 2015 09:51
-
-
Save key/ca2b49b2f53448fdef91 to your computer and use it in GitHub Desktop.
Convert `Byte Array` to `UInt8` in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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