Created
June 30, 2014 02:06
-
-
Save nolili/48fb7d1f81b6b54554a4 to your computer and use it in GitHub Desktop.
Swift C like array
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
// Array to NSData | |
var cArray:Array<UInt8> = [0x01, 0x02, 0x03] | |
var data = NSData(bytes:cArray, length:sizeof(UInt8) * cArray.count) | |
println(data) | |
// NSData to Array | |
var bufferArray:Array<UInt8> = [0x00, 0x00, 0x00] | |
data.getBytes(&bufferArray, length:3) | |
println(bufferArray) | |
// Bitwise Operators | |
var a:UInt16 = UInt16(bufferArray[0]) | |
var b:UInt16 = UInt16(bufferArray[1]) | |
var result:UInt16 = 0 | |
b = b << 4 | |
result = a | b | |
println(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment