Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created September 8, 2023 08:40
Show Gist options
  • Save laevandus/a046cec8d222c95a4e1db1912f59649e to your computer and use it in GitHub Desktop.
Save laevandus/a046cec8d222c95a4e1db1912f59649e to your computer and use it in GitHub Desktop.
var input = UInt16(1024)
// UInt16 -› Data
let data = Data(bytes: &input, count: MemoryLayout<UInt16>.size)
// Data -> UInt16
let output = data.withUnsafeBytes({ $0.load(as: UInt16.self) })
print(output) // 1024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment