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 

方法(请参阅数据转换。swift(,所以您可以做的是

let bi: BigInt = ...
let bytes = Array(BigUInt(bi).serialize())

最新更新