Skip to content

quadrate-language/hex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hex

Hexadecimal encoding and decoding for Quadrate.

Installation

quadpm install https://github.com/quadrate-language/hex

Usage

use 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
}

API

Functions

  • encode(s:str -- hex:str) - Encode string to uppercase hex
  • encode_lower(s:str -- hex:str) - Encode string to lowercase hex
  • decode(hex:str -- s:str) - Decode hex string to bytes
  • encode_byte(b:i64 -- hex:str) - Encode single byte to 2-char hex
  • decode_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 hex
  • decoded_len(hex:str -- len:i64) - Get decoded length (-1 if invalid)
  • encoded_len(s:str -- len:i64) - Get encoded length

License

MIT

About

Quadrate hexadecimal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published