A library for converting between Data
and Hexadecimal (also known as Base-16) strings.
// This is the original data.
let data: Data = "1234JKLM".data(using: .utf8)!
// Perform encoding.
let hexString: String = data.hexEncodedString()
print(hexString)
// -> "313233344a4b4c4d"
// This is the Hexadecimal encoded string.
let hexString: String = "313233344a4b4c4d"
// Perform decoding.
let data: Data = Data(hexEncoded: hexString)!
print(String(decoding: data, as: UTF8.self))
// -> "1234JKLM"
The documentation is available on Swift Package Index.
Add the dependency to your Package.swift
. For example:
// swift-tools-version: 5.8
import PackageDescription
let package = Package(
name: "MyPackage",
dependencies: [
// Add `Hex.swift` package here.
.package(url: "https://github.com/yaslab/Hex.swift.git", from: "1.0.0")
],
targets: [
.executableTarget(
name: "MyCommand",
dependencies: [
// Then add it to your module's dependencies.
.product(name: "Hex", package: "Hex.swift")
]
)
]
)
Hex.swift is released under the MIT license. See the LICENSE file for more info.