James
James

Reputation: 363

Swift BigInt to [UInt8]

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

Upvotes: 0

Views: 1444

Answers (1)

Martin R
Martin R

Reputation: 539975

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())

Upvotes: 2

Related Questions