Skip to content

<convert.h>

Number and string conversion, and byte-order helpers.

#include <convert.h>

Constants

Name Value Description
ntohs htons Network to host order, 16-bit; the same swap as htons().
ntohl htonl Network to host order, 32-bit; the same swap as htonl().

Functions

atoh

int atoh(const char *str);

Convert a hexadecimal string to an integer.

Skips leading whitespace, accepts a sign, and stops at the first non-hex character. No "0x" prefix and no overflow check.

Parameter Direction Description
str in Pointer to the null-terminated hexadecimal string.

Returns: The converted integer value.

itoa

char * itoa(int value, char *str, unsigned int base);

Convert a signed integer to a string.

Parameter Direction Description
value in Integer value to convert.
str out Pointer to the buffer where the resulting string will be stored.
base in Numerical base, 2 to 36; digits above 9 are lowercase.

Returns: Pointer to the resulting string. The caller MUST ensure the buffer is large enough.

utoa

char * utoa(unsigned int value, char *str, unsigned int base);

Convert an unsigned integer to a string.

Parameter Direction Description
value in Unsigned integer value to convert.
str out Pointer to the buffer where the resulting string will be stored.
base in Numerical base, 2 to 36; digits above 9 are lowercase.

Returns: Pointer to the resulting string. The caller MUST ensure the buffer is large enough.