Swift BigInt转为[UInt8] [英] Swift BigInt to [UInt8]

查看:407
本文介绍了Swift BigInt转为[UInt8]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用swift 4,并且正在使用BigInt的以下实现: https://github.com/attaswift/BigInt

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

我注意到没有将BigInt或NSDecimalNumber转换为[UInt8]的本机方法,你们中的任何人都知道该方法的良好实现,因为我找不到它.

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.

谢谢

推荐答案

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),所以您可以做的是

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

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

这篇关于Swift BigInt转为[UInt8]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆