Skip to content

Instantly share code, notes, and snippets.

@nolili
Created June 30, 2014 02:06
Show Gist options
  • Save nolili/48fb7d1f81b6b54554a4 to your computer and use it in GitHub Desktop.
Save nolili/48fb7d1f81b6b54554a4 to your computer and use it in GitHub Desktop.
Swift C like array
// 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