Swift BigInt to [UInt8]

浪子不回头ぞ 提交于 2020-01-06 06:49:47

问题


I am using swift 4 and am using this implementation of BigInt: https://github.com/attaswift/BigInt

I noticed there are no native methods to convert a BigInt or NSDecimalNumber into a [UInt8], do any of you know a good implementation of this as I have not been able to find one.

Thank you


回答1:


BigUInt has a

/// Return a `Data` value that contains the base-256 representation of this integer,
/// in network (big-endian) byte order.
public func serialize() -> Data 

method (see Data Conversion.swift), so what you can do is

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


来源:https://stackoverflow.com/questions/48987069/swift-bigint-to-uint8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!