Encode and decode hex strings
import Voltaire
let bytes: [UInt8] = [0xde, 0xad, 0xbe, 0xef]
let hex = Hex.encode(bytes) // "0xdeadbeef"
let roundtrip = try Hex.decode(hex)
XCTAssertEqual(roundtrip, bytes)
// Foundation.Data support
import Foundation
let data = Data([0xca, 0xfe])
XCTAssertEqual(Hex.encode(data), "0xcafe")
Was this page helpful?