Welcome to little lamb

Code » limb » master » tree

[master] / src / doc / u32.h / u32_fmt.3.md

% limb manual
% u32_fmt(3)
% limb 0.1.0
% 2023-07-24

# NAME

u32_fmt, u32_fmtg, u32_0fmt - write an u32 as decimal value into a byte array

u32_xfmt, u32_0xfmt - write an u32 as hexadecimal value into a byte array

u32_ofmt, u32_0ofmt - write an u32 as octal value into a byte array

u32_bfmt, u32_0bfmt - write an u32 as binary value into a byte array


# SYNOPSIS

    #include <limb/u32.h>

```pre hl
size_t u32_fmt(char *<em>s</em>, u32 <em>u</em>)
size_t u32_0fmt(char *<em>s</em>, u32 <em>u</em>, size_t <em>min</em>)

size_t u32_fmtg(char *<em>s</em>, u32 <em>u</em>)
size_t u32_0fmtg(char *<em>s</em>, u32 <em>u</em>, size_t <em>min</em>)

size_t u32_xfmt(char *<em>s</em>, u32 <em>u</em>)
size_t u32_0xfmt(char *<em>s</em>, u32 <em>u</em>, size_t <em>min</em>)

size_t u32_ofmt(char *<em>s</em>, u32 <em>u</em>)
size_t u32_0ofmt(char *<em>s</em>, u32 <em>u</em>, size_t <em>min</em>)

size_t u32_bfmt(char *<em>s</em>, u32 <em>u</em>)
size_t u32_0bfmt(char *<em>s</em>, u32 <em>u</em>, size_t <em>min</em>)
```

# DESCRIPTION

The `u32_fmt`() macro will write into `s` the value of `u` in decimal.
The `u32_0fmt`() macro will write into `s` the value of `u` in decimal,
prefixing it with leading zeroes if it requires less than `min` characters to do
so.

The `u32_fmtg`() and `u32_0fmtg`() macros are similar, only they will use a
coma (`,`) as thousand separator as needed.

The `u32_xfmt`() and `u32_0xfmt`() macros are similar, only putting the value
of `u` in hexadecimal.

The `u32_ofmt`() and `u32_0ofmt`() macros are similar, only putting the value
of `u` in octal.

The `u32_bfmt`() and `u32_0bfmt`() macros are similar, only putting the value
of `u` in binary.

It is possible to use `NULL` as `s` to only have length computation performed.

! INFO: Generic functions
! Note that those are macros to [u64_fmt_generic](3) and [u64_0fmt_generic](3).

## Constants

Some constants are available if needed, e.g. to allocate a buffer large enough :

: *U32_FMT*
:: Maximum number of `char` needed to hold a decimal string

: *U32_FMTG*
:: Maximum number of `char` needed to hold a thousand-separated decimal string

: *U32_XFMT*
:: Maximum number of `char` needed to hold an hexadecimal string

: *U32_OFMT*
:: Maximum number of `char` needed to hold an octal string

: *U32_BFMT*
:: Maximum number of `char` needed to hold a binary string

Note that all of those include an extra `char` for a proper NUL-terminated
string.

# RETURN VALUE

All of these return the length of the string written into `s`, or required to
do so when `s` is `NULL`