如何在 swift 中创建一个接受任何类型的 Int 或 Uint 的函数 (并计算参数类型所需的位数)
最佳答案
String
有构造函数
init<T : _SignedIntegerType>(_ v: T, radix: Int, uppercase: Bool = default)
init<T : _UnsignedIntegerType>(_ v: T, radix: Int, uppercase: Bool = default)
可以在这里使用:
let num = 100
let str = String(num, radix: 2)
print(str)
// Output: 1100100
关于swift - 使用 Swift 生成整数二进制表示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24986319/