Math Processor Unit Library

libmpu – library of arithmetic functions for integer, real, and complex numbers of increased digit capacity

16 Commits   0 Branches   2 Tags
.TH iatoi 3  "December 27, 2024" "libmpu" "LibMPU Programmer's Manual"
.SH NAME
\fBiatoi\fP, \fBiatoui\fP \- functions for converting ASCII string to integer number
.SH SYNOPSIS
.nf
.B #include <libmpu.h>
.PP
.BI "void iatoi( mpu_int *" c ", __mpu_char8_t *" str ", int " nb " );
.BI "void iatoui( mpu_int *" c ", __mpu_char8_t *" str ", int " nb " );
.fi
.SH DESCRIPTION
The \fBiatoi()\fP, \fBiatoui()\fP functions are used to convert an ASCII string into numeric form.
In the case of \fBiatoi()\fP function, the \fBstr\fP argument is considered as a pointer to a character
array containing characters of a signed integer; in the case of \fBiatoui()\fP function, it is assumed
that the string contains a representation of an unsigned integer type numeric constant.
.PP
Numeric constants in a string can be represented as binary, octal, hexadecimal, and decimal numbers.
Binary numbers begin with the prefix \fB0b\fP or \fB0B\fP, for example, \fB0b1011\fP. The octal numbers
must begin with '0' and contain digits from '0' through '7'. Hexadecimal constants begin with the prefix
\fB0x\fP or \fB0X\fP and can contain characters from '0' to '7' and characters from 'a' to 'f' in any case.
Decimal constants can contain characters from '0' to '9' but must not start with '0'. Before a number
signs '+', '-' are allowed. If a string contains a binary, octal or hexadecimal constant, the sign
is ignored.
.PP
The result is placed at \fBc\fP, and the parameter \fBnb\fP represents the size of the result \fBc\fP
in bytes.
.PP
If the number represented in the \fBstr\fP string does not fit into the specified (\fBnb\fP) format, the
overflow flag (\fBO\fP) is set.
.PP
The function affects the flags \fBA\fP, \fBC\fP, \fBO\fP, \fBP\fP, \fBS\fP, \fBZ\fP. Flags \fBA\fP, \fBC\fP
flags are reset to 0. The flag \fBR\fP is not changed.
.sp
.SH EXAMPLES
.nf
.sp
#include <libmpu.h>
#include <stdio.h>

int main( void )
{
  int  rc = 0;

  __mpu_init();
  __mpu_extra_warnings = 1;

  {
    mpu_int16_t    a, b;
    int            nb = NB_I16;
    __mpu_char8_t  s[32];

    iatoui( a, "0b11", nb ); /* evaluate the A variable */
    iatoi( b,  "-3", nb );   /* evaluate the B variable */

    iitoa( s, a, RADIX_DEC, LOWERCASE, nb ); /* convert A value to ASCII string S */
    printf( "a = %s;\\n", s ); /* a = 3; */

    iitoa( s, b, RADIX_BIN, LOWERCASE, nb ); /* convert B value to ASCII string S */
    printf( "b = %s;\\n", s ); /* b = 0b1111111111111101; */
  }

  __mpu_free_context();

  return( rc );
}
.fi
.SH SEE ALSO
.BR iadd(3),
.BR isub(3),
.BR iadc(3),
.BR isbb(3),
.BR ishl(3),
.BR ishr(3),
.BR isal(3),
.BR isar(3),
.BR irol(3),
.BR iror(3),
.BR ircl(3),
.BR ircr(3),
.BR ishln(3),
.BR ishrn(3),
.BR isaln(3),
.BR isarn(3),
.BR iroln(3),
.BR irorn(3),
.BR ircln(3),
.BR ircrn(3),
.BR ineg(3),
.BR inot(3),
.BR iand(3),
.BR itest(3),
.BR icmp(3),
.BR ior(3),
.BR ixor(3),
.BR iinc(3),
.BR idec(3),
.BR ixchg(3),
.BR icpy(3),
.BR icvt(3),
.BR imul(3),
.BR ismul(3),
.BR idiv(3),
.BR isdiv(3),
.BR iitoa(3),
.BR iuitoa(3).