如何将负Int64打包到字节数组中

时间:2017-03-13 11:44:36

标签: swift

我在尝试将Int64转换为字节数组时遇到问题。 value为否定时,应用失败。

这就是我在操场上的内容:

let value: Int64 = -1

let byte1: UInt8 = UInt8((value >> 56) | Int64(0xFF))
let byte2: UInt8 = UInt8((value >> 48) | Int64(0xFF))
let byte3: UInt8 = UInt8((value >> 40) | Int64(0xFF))
let byte4: UInt8 = UInt8((value >> 32) | Int64(0xFF))
let byte5: UInt8 = UInt8((value >> 24) | Int64(0xFF))
let byte6: UInt8 = UInt8((value >> 16) | Int64(0xFF))
let byte7: UInt8 = UInt8((value >> 8) | Int64(0xFF))
let byte8: UInt8 = UInt8(value & Int64(0xFF))

我不确定(现在无法检查)但是相同的代码在c ++ - port中工作。

0 个答案:

没有答案