Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
学术性质的问题: 如何将值为 -1 的 Int32 的字节数据转换为 UInt32?(SWIFT 能做到吗?)
理解: 我知道-1不是一个可以用无符号整数表示的值,因为UInts只包含-1以上的整数
但是我也知道 Int32 和 UInt32 在 Bytes (4*8=32)中占用相同数量的空间。该字节空间应该能够用于任何一种类型,无论它是否代表相同的值......它显然不会。
结论: 应该有一些简单的方法来获取 Int32 的原始位数据并将其用于 UInt32 ......
通过 bitPattern 转换变量(感谢 Jthora)。为此,这里有很多帮助:
对于 32 位,有符号时为 0xffffffff=> -1,无符号时为 4294967295。