hex2bin()

hex2bin()#

hex2bin converts a hexadecimal string into its binary representation, storing the result in a provided buffer.

Prototype

char *hex2bin(
    char *bf,     /* Output buffer for binary data */
    int bfsize,   /* Size of the output buffer */
    const char *hex, /* Input hexadecimal string */
    size_t hex_len,  /* Length of the input hexadecimal string */
    size_t *out_len  /* Output length of the binary data */
);

Parameters

Key

Type

Description

bf

char *

Pointer to the output buffer where the binary data will be stored.

bfsize

int

Size of the output buffer in bytes.

hex

const char *

Pointer to the input hexadecimal string to be converted.

hex_len

size_t

Length of the input hexadecimal string.

out_len

size_t *

Pointer to a variable where the function will store the length of the resulting binary data.


Return Value

Returns a pointer to the output buffer bf containing the binary data.

Notes

[‘The function processes the input hexadecimal string two characters at a time, converting them into a single byte.’, ‘If a non-hexadecimal character is encountered, the conversion stops.’, ‘The function does not allocate memory; the caller must ensure bf has enough space.’, ‘The out_len parameter is optional; if provided, it will contain the number of bytes written to bf.’]

Prototype

// Not applicable in JS

Prototype

# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples