Last active
December 21, 2016 22:48
-
-
Save key/56972ab53b7ff9bf42be to your computer and use it in GitHub Desktop.
Convert `Double` value to `NSData` 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
var x: Double = 0.99043125417 | |
var length = sizeof(Double) // -> 8 | |
var x_data = NSData(bytes: &x, length: length) | |
var buffer = [UInt8](count: sizeof(Double), repeatedValue: 0x00) | |
x_data.getBytes(&buffer, length: buffer.count) | |
print(buffer) // -> "[210, 21, 179, 226, 156, 177, 239, 63]\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment