Swift BigInt 到 [UInt8]
Swift BigInt to [UInt8]
我正在使用 swift 4 并且正在使用 BigInt 的这个实现:https://github.com/attaswift/BigInt
我注意到没有将 BigInt 或 NSDecimalNumber 转换为 [UInt8] 的本机方法,你们中有人知道这个的良好实现吗,因为我找不到一个。
谢谢
BigUInt
有一个
/// Return a `Data` value that contains the base-256 representation of this integer,
/// in network (big-endian) byte order.
public func serialize() -> Data
方法(参见Data Conversion.swift),所以你可以做的是
let bi: BigInt = ...
let bytes = Array(BigUInt(bi).serialize())
我正在使用 swift 4 并且正在使用 BigInt 的这个实现:https://github.com/attaswift/BigInt
我注意到没有将 BigInt 或 NSDecimalNumber 转换为 [UInt8] 的本机方法,你们中有人知道这个的良好实现吗,因为我找不到一个。
谢谢
BigUInt
有一个
/// Return a `Data` value that contains the base-256 representation of this integer,
/// in network (big-endian) byte order.
public func serialize() -> Data
方法(参见Data Conversion.swift),所以你可以做的是
let bi: BigInt = ...
let bytes = Array(BigUInt(bi).serialize())