-
-
Save vukcevich/151322f01c9789a77c1d7f5ff04572bf 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