std/encoding/hex

The std/encoding/hex module provides utilities for hexadecimal encoding and decoding of data.

Overview

Usage

import "std/encoding/hex.zc"
import "std/io.zc"

fn main() {
    let data = "Hello";
    let encoded = Hex::encode((u8*)data, 5);
    println(f"Hex: {encoded}"); // 48656c6c6f
    
    let decoded_res = Hex::decode(encoded);
    if (decoded_res.is_ok()) {
        let bytes = decoded_res.unwrap();
        // Use bytes...
    }
}

Struct Definition

struct Hex {}

Methods

Hex Methods

MethodSignatureDescription
encodeHex::encode(data: u8*, len: usize) -> StringEncodes raw data into a hexadecimal string.
decodeHex::decode(hex: String) -> Result<Vec<u8>>Decodes a hexadecimal string into a Vec<u8>.