@need 3200

@node Converting Between Numbers and Strings
@chapter Converting Between Numbers and Strings

The functions in this chapter convert between numbers and ASCII strings.


@strong{NOTE:} Floating point conversions are not included with this release
of the Hackerlab C Library.  They will be included in a future
release.

@need 3200

@section Converting Integers to and from Strings

The functions in this chapter convert between integer types and
strings.

@menu
* Converting Integers to Strings::
* Converting Decimal Strings to Integers::
* Converting Hexadecimal Strings to Integers::
* Converting Octal Strings to Integers::
@end menu

@need 3200

@node Converting Integers to Strings
@subsection Converting Integers to Strings
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_ulong_to_decimal}@fuindex cvt_ulong_to_decimal
@*
@example
@group
void cvt_ulong_to_decimal (t_uchar * nbuf, unsigned long n);
@end group
@group
@end group
@end example

Convert @code{n} to a 0-terminated decimal number.

@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_long_to_decimal}@fuindex cvt_long_to_decimal
@*
@example
@group
void cvt_long_to_decimal (t_uchar * nbuf, long n);
@end group
@group
@end group
@end example

Convert @code{n} to a 0-terminated decimal number.

@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_ulong_to_octal}@fuindex cvt_ulong_to_octal
@*
@example
@group
void cvt_ulong_to_octal (t_uchar * nbuf, unsigned long n);
@end group
@group
@end group
@end example

Convert @code{n} to a 0-terminated octal number.

@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_long_to_octal}@fuindex cvt_long_to_octal
@*
@example
@group
void cvt_long_to_octal (t_uchar * nbuf, long n);
@end group
@group
@end group
@end example

Convert @code{n} to a 0-terminated octal number.

@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_ulong_to_HEX}@fuindex cvt_ulong_to_HEX
@*
@example
@group
void cvt_ulong_to_HEX (t_uchar * nbuf, unsigned long n);
@end group
@group
@end group
@end example

Convert @code{n} to a 0-terminated hexadecimal number using upper-case
hex digits @geindex A..F
@dfn{A..F}.

@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_long_to_HEX}@fuindex cvt_long_to_HEX
@*
@example
@group
void cvt_long_to_HEX (t_uchar * nbuf, long n);
@end group
@group
@end group
@end example

Convert @code{n} to a 0-terminated hexadecimal number using upper-case
hex digits @geindex A..F
@dfn{A..F}.

@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_ulong_to_hex}@fuindex cvt_ulong_to_hex
@*
@example
@group
void cvt_ulong_to_hex (t_uchar * nbuf, unsigned long n);
@end group
@group
@end group
@end example

Convert @code{n} to a 0-terminated hexadecimal number using lower-case
hex digits @geindex a..f
@dfn{a..f}.

@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_long_to_hex}@fuindex cvt_long_to_hex
@*
@example
@group
void cvt_long_to_hex (t_uchar * nbuf, long n);
@end group
@group
@end group
@end example

Convert @code{n} to a 0-terminated hexadecimal number using lower-case
hex digits @geindex a..f
@dfn{a..f}.




@need 3200

@node Converting Decimal Strings to Integers
@subsection Converting Decimal Strings to Integers
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_decimal_to_ulong}@fuindex cvt_decimal_to_ulong
@*
@example
@group
int cvt_decimal_to_ulong (int * errn,
                          unsigned long * answerp,
                          const t_uchar * text,
                          size_t len);
@end group
@group
@end group
@end example

Convert the decimal number @code{text} to an unsigned long integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE  the decimal number will not fit in an `unsigned long'.
     EINVAL  `text' is not a valid decimal number.
@end group
@group
@end group
@end example
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_decimal_to_uint}@fuindex cvt_decimal_to_uint
@*
@example
@group
int cvt_decimal_to_uint (int * errn,
                         unsigned int * answerp,
                         const t_uchar * text,
                         size_t len);
@end group
@group
@end group
@end example

Convert the decimal number @code{text} to an unsigned integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE  the decimal number will not fit in an `unsigned int'.
     EINVAL  `text' is not a valid decimal number.
@end group
@group
@end group
@end example
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_decimal_to_long}@fuindex cvt_decimal_to_long
@*
@example
@group
int cvt_decimal_to_long (int * errn,
                         long * answerp,
                         const t_uchar * text,
                         size_t len);
@end group
@group
@end group
@end example

Convert the decimal number @code{text} to a long integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE          the decimal number will not fit in a `long'.
     EINVAL          `text' is not a valid decimal number.
@end group
@group
@end group
@end example
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_decimal_to_int}@fuindex cvt_decimal_to_int
@*
@example
@group
int cvt_decimal_to_int (int * errn,
                        int * answerp,
                        const t_uchar * text,
                        size_t len);
@end group
@group
@end group
@end example

Convert the decimal number @code{text} to an integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE          the decimal number will not fit in an `int'.
     EINVAL          `text' is not a valid decimal number.
@end group
@group
@end group
@end example



@need 3200

@node Converting Hexadecimal Strings to Integers
@subsection Converting Hexadecimal Strings to Integers
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_hex_to_ulong}@fuindex cvt_hex_to_ulong
@*
@example
@group
int cvt_hex_to_ulong (int * errn,
                      unsigned long * answerp,
                      const t_uchar * text,
                      size_t len);
@end group
@group
@end group
@end example

Convert the hexadecimal number @code{text} to an unsigned long integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE  the hexadecimal number will not fit in an `unsigned long'.
     EINVAL  `text' is not a valid hexadecimal number.
@end group
@group
@end group
@end example
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_hex_to_uint}@fuindex cvt_hex_to_uint
@*
@example
@group
int cvt_hex_to_uint (int * errn,
                     unsigned int * answerp,
                     const t_uchar * text,
                     size_t len);
@end group
@group
@end group
@end example

Convert the hexadecimal number @code{text} to an unsigned integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE  the hexadecimal number will not fit in an `unsigned int'.
     EINVAL  `text' is not a valid hexadecimal number.
@end group
@group
@end group
@end example
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_hex_to_long}@fuindex cvt_hex_to_long
@*
@example
@group
int cvt_hex_to_long (int * errn,
                     long * answerp,
                     const t_uchar * text,
                     size_t len);
@end group
@group
@end group
@end example

Convert the hexadecimal number @code{text} to a long integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE          the hexadecimal number will not fit in a `long'.
     EINVAL          `text' is not a valid hexadecimal number.
@end group
@group
@end group
@end example
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_hex_to_int}@fuindex cvt_hex_to_int
@*
@example
@group
int cvt_hex_to_int (int * errn,
                    int * answerp,
                    const t_uchar * text,
                    size_t len);
@end group
@group
@end group
@end example

Convert the hexadecimal number @code{text} to an integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE          the hexadecimal number will not fit in an `int'.
     EINVAL          `text' is not a valid hexadecimal number.
@end group
@group
@end group
@end example



@need 3200

@node Converting Octal Strings to Integers
@subsection Converting Octal Strings to Integers
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_octal_to_ulong}@fuindex cvt_octal_to_ulong
@*
@example
@group
int cvt_octal_to_ulong (int * errn,
                        unsigned long * answerp,
                        const t_uchar * text,
                        size_t len);
@end group
@group
@end group
@end example

Convert the octal number @code{text} to an unsigned long integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE  the octal number will not fit in an `unsigned long'.
     EINVAL  `text' is not a valid octal number.
@end group
@group
@end group
@end example
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_octal_to_uint}@fuindex cvt_octal_to_uint
@*
@example
@group
int cvt_octal_to_uint (int * errn,
                         unsigned int * answerp,
                         const t_uchar * text,
                         size_t len);
@end group
@group
@end group
@end example

Convert the octal number @code{text} to an unsigned integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE  the octal number will not fit in an `unsigned int'.
     EINVAL  `text' is not a valid octal number.
@end group
@group
@end group
@end example
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_octal_to_long}@fuindex cvt_octal_to_long
@*
@example
@group
int cvt_octal_to_long (int * errn,
                         long * answerp,
                         const t_uchar * text,
                         size_t len);
@end group
@group
@end group
@end example

Convert the octal number @code{text} to a long integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE          the octal number will not fit in a `long'.
     EINVAL          `text' is not a valid octal number.
@end group
@group
@end group
@end example
@sp 1
@need 1750
@noindent
@b{* Function} @code{cvt_octal_to_int}@fuindex cvt_octal_to_int
@*
@example
@group
int cvt_octal_to_int (int * errn,
                        int * answerp,
                        const t_uchar * text,
                        size_t len);
@end group
@group
@end group
@end example

Convert the octal number @code{text} to an integer.


Return @code{0} upon success, @code{-1} on error.


On error, @code{*errn} may be:

@example
@group
     ERANGE          the octal number will not fit in an `int'.
     EINVAL          `text' is not a valid octal number.
@end group
@group
@end group
@end example









