MLIB
Loading...
Searching...
No Matches
hex.cpp File Reference

Utility functions for strings of hex characters. More...

#include <mlib/mlib.h>

Functions

void mlib::binhex (char *dst, const unsigned char *src, size_t sz)
 convert binary data to a string of hex digits
 
void mlib::bytehex (char *dst, unsigned char bin)
 convert one byte to two hex digits
 
void mlib::shorthex (char *dst, unsigned short bin)
 convert a short integer to 4 hex digits
 
void mlib::longhex (char *dst, unsigned long bin)
 convert a long integer to 8 hex digits
 
bool mlib::hexbyte (unsigned char &dst, const char *src)
 convert two ASCII hex digits to binary
 
bool mlib::hexshort (unsigned short &dst, const char *src)
 convert four ASCII hex digits to binary
 
bool mlib::hexlong (unsigned long &dst, const char *src)
 convert eight ASCII hex digits to binary
 
size_t mlib::hexbin (unsigned char *dst, const char *src, size_t sz)
 convert a string of hex digits to binary
 

Detailed Description

Utility functions for strings of hex characters.

Function Documentation

◆ binhex()

void mlib::binhex ( char * str,
const unsigned char * bin,
size_t sz )

convert binary data to a string of hex digits

Parameters
stroutput string
bininput binary data
szsize of binary data

The output string is null-terminated. It must be at least 2*sz+1 bytes.

◆ bytehex()

void mlib::bytehex ( char * str,
unsigned char bin )

convert one byte to two hex digits

Parameters
stroutput string. Must be at least 3 bytes long
bininput binary value

The output string is null-terminated.

◆ hexbin()

size_t mlib::hexbin ( unsigned char * bin,
const char * str,
size_t sz )

convert a string of hex digits to binary

Parameters
binresulting binary data
strinput hex string
szmaximum size of binary data
Returns
number of bytes converted

◆ hexbyte()

bool mlib::hexbyte ( unsigned char & bin,
const char * str )

convert two ASCII hex digits to binary

Parameters
binresulting byte value
strinput string of hex digits
Returns
true if conversion was successful, false otherwise

◆ hexlong()

bool mlib::hexlong ( unsigned long & bin,
const char * str )

convert eight ASCII hex digits to binary

Parameters
binresulting long integer value
strinput string of hex digits
Returns
true if conversion was successful, false otherwise

◆ hexshort()

bool mlib::hexshort ( unsigned short & bin,
const char * str )

convert four ASCII hex digits to binary

Parameters
binresulting short integer value
strinput string of hex digits
Returns
true if conversion was successful, false otherwise

◆ longhex()

void mlib::longhex ( char * str,
unsigned long bin )

convert a long integer to 8 hex digits

Parameters
stroutput string. Must be at least 9 bytes long
bininput binary value

The output string is null-terminated.

◆ shorthex()

void mlib::shorthex ( char * str,
unsigned short bin )

convert a short integer to 4 hex digits

Parameters
stroutput string. Must be at least 5 bytes long
bininput binary value

The output string is null-terminated.