【发布时间】:2018-01-21 21:38:43
【问题描述】:
我想将 Hexa 值转换为十进制。所以我试过这个。当值> 0时,它工作正常。但是当 value 为
let h2 = “0373”
let d4 = Int(h2, radix: 16)!
print(d4) // 883
let h3 = “FF88”
let d5 = Int(h3, radix: 16)!
print(d5) // 65416
当我通过FF88时,它返回65416。但实际上是-120。
现在,我正在关注这个Convert between Decimal, Binary and Hexadecimal in Swift 的答案。但它并不总是有效。
请查看此对话online。有关此对话的更多详细信息,请参见下图。
有没有其他解决方案可以从 Hexa 值中得到负小数?
任何帮助将不胜感激!
【问题讨论】: