Convert NSDecimalNumber to hex String

269 Views Asked by At

I managed to convert a NSDecimalNumber to a hex String using BInt library. Here is my code:

public func toDecimalHex(value: NSDecimalNumber) -> String{
    let bint = BInt(value.stringValue)
    return (bint?.asString(radix: 16))!
}

example:

let number = NSDecimalNumber(string: "1000000000000000000000000")
let hex = toDecimalHex(value: number)

//result : d3c21bcecceda1000000

Basically, how can I convert without using any library like BInt? This brings too much overhead. I just want to get rid of it.

0

There are 0 best solutions below