hexEncodedString (BitFoundation/Data+Hex.swift)

bitchat · localPackages/BitFoundation/Sources/BitFoundation/Data+Hex.swift · swift · Unlicense
security

Data+Hex.swift BitFoundation This is free and unencumbered software released into the public domain. For more information, see <https://unlicense.org>

// Source: https://github.com/permissionlesstech/bitchat | License: Unlicense
// Provided via justclaw.it.com; keep this notice with the code.
//
// Data+Hex.swift
// BitFoundation
//
// This is free and unencumbered software released into the public domain.
// For more information, see <https://unlicense.org>
//

import struct Foundation.Data

public extension Data {
    func hexEncodedString() -> String {
        if self.isEmpty {
            return ""
        }
        return self.map { String(format: "%02x", $0) }.joined()
    }

    /// Initialize Data from a hex string.
    /// - Parameter hexString: A hex string, optionally prefixed with "0x" or "0X".
    ///   Whitespace is trimmed. Must have even length after prefix removal.
    /// - Returns: nil if the string has odd length or c

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key