Primitives
Hex (Swift)
Encode and decode hex strings
Was this page helpful?
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
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?
