Hexadecimal encoding and decoding for Quadrate.
quadpm install https://github.com/quadrate-language/hexuse hex
fn main() {
// Encode to uppercase hex
"Hello" hex::encode -> h
h print nl // "48656C6C6F"
// Encode to lowercase hex
"Hello" hex::encode_lower -> h2
h2 print nl // "48656c6c6f"
// Decode hex string
"48656C6C6F" hex::decode -> s
s print nl // "Hello"
// Single byte operations
65 hex::encode_byte -> b
b print nl // "41"
"41" hex::decode_byte -> v
v print nl // 65
// Validation
"48656C6C6F" hex::is_valid -> valid
valid print nl // 1
}
encode(s:str -- hex:str)- Encode string to uppercase hexencode_lower(s:str -- hex:str)- Encode string to lowercase hexdecode(hex:str -- s:str)- Decode hex string to bytesencode_byte(b:i64 -- hex:str)- Encode single byte to 2-char hexdecode_byte(hex:str -- b:i64)- Decode 2-char hex to byte (-1 if invalid)is_valid(hex:str -- valid:i64)- Check if string is valid hexdecoded_len(hex:str -- len:i64)- Get decoded length (-1 if invalid)encoded_len(s:str -- len:i64)- Get encoded length
MIT