std/encoding/hex

std/encoding/hex 模組提供了用於數據十六進位編碼和解碼的工具。

概覽

使用方法

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

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

結構體定義

struct Hex {}

方法

Hex 方法

方法簽名說明
encodeHex::encode(data: u8*, len: usize) -> String將原始數據編碼為十六進位字串。
decodeHex::decode(hex: String) -> Result<Vec<u8>>將十六進位字串解碼為 Vec<u8>。