le_hex.h File Reference

Go to the source code of this file.

Functions

int32_t le_hex_StringToBinary (const char *stringPtr, uint32_t stringLength, uint8_t *binaryPtr, uint32_t binarySize)
 
int32_t le_hex_BinaryToString (const uint8_t *binaryPtr, uint32_t binarySize, char *stringPtr, uint32_t stringSize)
 
int le_hex_HexaToInteger (const char *stringPtr)
 

Detailed Description

Legato Hex string API include file.

Function Documentation

◆ le_hex_BinaryToString()

int32_t le_hex_BinaryToString ( const uint8_t *  binaryPtr,
uint32_t  binarySize,
char *  stringPtr,
uint32_t  stringSize 
)

Convert a byte array into a string of uppercase hexadecimal characters.

Returns
number of characters written to stringPtr or -1 if stringSize is too small for binarySize
Note
the string written to stringPtr will be NULL terminated.
Parameters
[in]binaryPtrbinary array to convert
[in]binarySizesize of binary array
[out]stringPtrhex string array, terminated with '\0'.
[in]stringSizesize of string array. Must be >= (2 * binarySize) + 1

◆ le_hex_HexaToInteger()

int le_hex_HexaToInteger ( const char *  stringPtr)

Convert a NULL terminated string of valid hexadecimal characters [0-9a-fA-F] into an integer.

Returns
  • Positive integer corresponding to the hexadecimal input string
  • -1 if the input contains an invalid character or the value will not fit in an integer
Parameters
[in]stringPtrstring of hex chars to convert into an int

◆ le_hex_StringToBinary()

int32_t le_hex_StringToBinary ( const char *  stringPtr,
uint32_t  stringLength,
uint8_t *  binaryPtr,
uint32_t  binarySize 
)

Convert a string of valid hexadecimal characters [0-9a-fA-F] into a byte array where each element of the byte array holds the value corresponding to a pair of hexadecimal characters.

Returns
  • number of bytes written into binaryPtr
  • -1 if the binarySize is too small or stringLength is odd or stringPtr contains an invalid character
Note
The input string is not required to be NULL terminated.
Parameters
[in]stringPtrstring to convert
[in]stringLengthstring length
[out]binaryPtrbinary result
[in]binarySizesize of the binary table. Must be >= stringLength / 2