41c271da (kx 2025-01-05 15:42:39 +0300 1) .TH iitoa 3 "December 27, 2024" "libmpu" "LibMPU Programmer's Manual"
41c271da (kx 2025-01-05 15:42:39 +0300 2) .SH NAME
41c271da (kx 2025-01-05 15:42:39 +0300 3) \fBiitoa\fP, \fBiuitoa\fP \- functions for converting an integer to an ASCII string
41c271da (kx 2025-01-05 15:42:39 +0300 4) .SH SYNOPSIS
41c271da (kx 2025-01-05 15:42:39 +0300 5) .nf
41c271da (kx 2025-01-05 15:42:39 +0300 6) .B #include <libmpu.h>
41c271da (kx 2025-01-05 15:42:39 +0300 7) .PP
41c271da (kx 2025-01-05 15:42:39 +0300 8) .BI "void iitoa( __mpu_char8_t *" str ", mpu_int *" a ", int " radix ", int " uf ", int " nb " );
41c271da (kx 2025-01-05 15:42:39 +0300 9) .BI "void iuitoa( __mpu_char8_t *" str ", mpu_int *" a ", int " radix ", int " uf ", int " nb " );
41c271da (kx 2025-01-05 15:42:39 +0300 10) .fi
41c271da (kx 2025-01-05 15:42:39 +0300 11) .SH DESCRIPTION
41c271da (kx 2025-01-05 15:42:39 +0300 12) The functions \fBiitoa()\fP, \fBiuitoa()\fP convert an integer variable located at \fBa\fP into
41c271da (kx 2025-01-05 15:42:39 +0300 13) a string constant. The base of the numerical system is selected according to the value of the
41c271da (kx 2025-01-05 15:42:39 +0300 14) parameter \fBradix\fP. Valid bases are presented in the header file \fBlibmpu.h\fP:
41c271da (kx 2025-01-05 15:42:39 +0300 15) .nf
41c271da (kx 2025-01-05 15:42:39 +0300 16) .sp
41c271da (kx 2025-01-05 15:42:39 +0300 17) #define RADIX_BIN 2
41c271da (kx 2025-01-05 15:42:39 +0300 18) #define RADIX_OCT 8
41c271da (kx 2025-01-05 15:42:39 +0300 19) #define RADIX_DEC 10
41c271da (kx 2025-01-05 15:42:39 +0300 20) #define RADIX_HEX 16
41c271da (kx 2025-01-05 15:42:39 +0300 21) .fi
41c271da (kx 2025-01-05 15:42:39 +0300 22) .sp
41c271da (kx 2025-01-05 15:42:39 +0300 23) If you select the base \fBRADIX_BIN\fP or \fBRADIX_HEX\fP, you can additionally select the prefix
41c271da (kx 2025-01-05 15:42:39 +0300 24) representation register with the parameter \fBuf\fP, the allowed values of which are:
41c271da (kx 2025-01-05 15:42:39 +0300 25) .nf
41c271da (kx 2025-01-05 15:42:39 +0300 26) .sp
41c271da (kx 2025-01-05 15:42:39 +0300 27) #define LOWERCASE 0
41c271da (kx 2025-01-05 15:42:39 +0300 28) #define UPPERCASE 1
41c271da (kx 2025-01-05 15:42:39 +0300 29) .fi
41c271da (kx 2025-01-05 15:42:39 +0300 30) .sp
41c271da (kx 2025-01-05 15:42:39 +0300 31) are also represented in the header file \fBlibmpu.h\fP.
41c271da (kx 2025-01-05 15:42:39 +0300 32) .PP
41c271da (kx 2025-01-05 15:42:39 +0300 33) The \fBnb\fP parameter specifies the size of the \fBa\fP variable in bytes.
41c271da (kx 2025-01-05 15:42:39 +0300 34) .PP
41c271da (kx 2025-01-05 15:42:39 +0300 35) The \fBiitoa()\fP, \fBiuitoa()\fP functions do not affect flags.
41c271da (kx 2025-01-05 15:42:39 +0300 36) .PP
41c271da (kx 2025-01-05 15:42:39 +0300 37) The size of memory allocated under the \fBstr\fP pointer must be sufficient to accommodate the resultant
41c271da (kx 2025-01-05 15:42:39 +0300 38) string constant.
41c271da (kx 2025-01-05 15:42:39 +0300 39) .PP
41c271da (kx 2025-01-05 15:42:39 +0300 40) The \fBiitoa()\fP function assumes that the \fBa\fP variable is a signed variable, and the \fBiuitoa()\fP
41c271da (kx 2025-01-05 15:42:39 +0300 41) function treats the argument as an unsigned integer. For example, an 8-bit binary integer \fB0b10000000\fP
41c271da (kx 2025-01-05 15:42:39 +0300 42) will be converted to the string "\-128" by the function \fBiitoa()\fP, while the function \fBiuitoa()\fP
41c271da (kx 2025-01-05 15:42:39 +0300 43) will output the positive number "128".
41c271da (kx 2025-01-05 15:42:39 +0300 44) .sp
41c271da (kx 2025-01-05 15:42:39 +0300 45) .SH EXAMPLES
41c271da (kx 2025-01-05 15:42:39 +0300 46) .nf
41c271da (kx 2025-01-05 15:42:39 +0300 47) .sp
41c271da (kx 2025-01-05 15:42:39 +0300 48) #include <libmpu.h>
41c271da (kx 2025-01-05 15:42:39 +0300 49) #include <stdio.h>
41c271da (kx 2025-01-05 15:42:39 +0300 50)
41c271da (kx 2025-01-05 15:42:39 +0300 51) int main( void )
41c271da (kx 2025-01-05 15:42:39 +0300 52) {
41c271da (kx 2025-01-05 15:42:39 +0300 53) int rc = 0;
41c271da (kx 2025-01-05 15:42:39 +0300 54)
41c271da (kx 2025-01-05 15:42:39 +0300 55) __mpu_init();
41c271da (kx 2025-01-05 15:42:39 +0300 56) __mpu_extra_warnings = 1;
41c271da (kx 2025-01-05 15:42:39 +0300 57)
41c271da (kx 2025-01-05 15:42:39 +0300 58) {
41c271da (kx 2025-01-05 15:42:39 +0300 59) mpu_int8_t a;
41c271da (kx 2025-01-05 15:42:39 +0300 60) int nb = NB_I8;
41c271da (kx 2025-01-05 15:42:39 +0300 61) __mpu_char8_t s[32];
41c271da (kx 2025-01-05 15:42:39 +0300 62)
41c271da (kx 2025-01-05 15:42:39 +0300 63) iatoui( a, "0b10000000", nb ); /* evaluate the A variable */
41c271da (kx 2025-01-05 15:42:39 +0300 64)
41c271da (kx 2025-01-05 15:42:39 +0300 65) iitoa( s, a, RADIX_DEC, LOWERCASE, nb ); /* convert A value to ASCII string S */
41c271da (kx 2025-01-05 15:42:39 +0300 66) printf( "a = %s;\\n", s ); /* a = -128; */
41c271da (kx 2025-01-05 15:42:39 +0300 67)
41c271da (kx 2025-01-05 15:42:39 +0300 68) iuitoa( s, a, RADIX_DEC, LOWERCASE, nb ); /* convert A value to ASCII string S */
41c271da (kx 2025-01-05 15:42:39 +0300 69) printf( "a = %s;\\n", s ); /* a = 128; */
41c271da (kx 2025-01-05 15:42:39 +0300 70) }
41c271da (kx 2025-01-05 15:42:39 +0300 71)
41c271da (kx 2025-01-05 15:42:39 +0300 72) __mpu_free_context();
41c271da (kx 2025-01-05 15:42:39 +0300 73)
41c271da (kx 2025-01-05 15:42:39 +0300 74) return( rc );
41c271da (kx 2025-01-05 15:42:39 +0300 75) }
41c271da (kx 2025-01-05 15:42:39 +0300 76) .fi
41c271da (kx 2025-01-05 15:42:39 +0300 77) .SH SEE ALSO
41c271da (kx 2025-01-05 15:42:39 +0300 78) .BR iadd(3),
41c271da (kx 2025-01-05 15:42:39 +0300 79) .BR isub(3),
41c271da (kx 2025-01-05 15:42:39 +0300 80) .BR iadc(3),
41c271da (kx 2025-01-05 15:42:39 +0300 81) .BR isbb(3),
41c271da (kx 2025-01-05 15:42:39 +0300 82) .BR ishl(3),
41c271da (kx 2025-01-05 15:42:39 +0300 83) .BR ishr(3),
41c271da (kx 2025-01-05 15:42:39 +0300 84) .BR isal(3),
41c271da (kx 2025-01-05 15:42:39 +0300 85) .BR isar(3),
41c271da (kx 2025-01-05 15:42:39 +0300 86) .BR irol(3),
41c271da (kx 2025-01-05 15:42:39 +0300 87) .BR iror(3),
41c271da (kx 2025-01-05 15:42:39 +0300 88) .BR ircl(3),
41c271da (kx 2025-01-05 15:42:39 +0300 89) .BR ircr(3),
41c271da (kx 2025-01-05 15:42:39 +0300 90) .BR ishln(3),
41c271da (kx 2025-01-05 15:42:39 +0300 91) .BR ishrn(3),
41c271da (kx 2025-01-05 15:42:39 +0300 92) .BR isaln(3),
41c271da (kx 2025-01-05 15:42:39 +0300 93) .BR isarn(3),
41c271da (kx 2025-01-05 15:42:39 +0300 94) .BR iroln(3),
41c271da (kx 2025-01-05 15:42:39 +0300 95) .BR irorn(3),
41c271da (kx 2025-01-05 15:42:39 +0300 96) .BR ircln(3),
41c271da (kx 2025-01-05 15:42:39 +0300 97) .BR ircrn(3),
41c271da (kx 2025-01-05 15:42:39 +0300 98) .BR ineg(3),
41c271da (kx 2025-01-05 15:42:39 +0300 99) .BR inot(3),
41c271da (kx 2025-01-05 15:42:39 +0300 100) .BR iand(3),
41c271da (kx 2025-01-05 15:42:39 +0300 101) .BR itest(3),
41c271da (kx 2025-01-05 15:42:39 +0300 102) .BR icmp(3),
41c271da (kx 2025-01-05 15:42:39 +0300 103) .BR ior(3),
41c271da (kx 2025-01-05 15:42:39 +0300 104) .BR ixor(3),
41c271da (kx 2025-01-05 15:42:39 +0300 105) .BR iinc(3),
41c271da (kx 2025-01-05 15:42:39 +0300 106) .BR idec(3),
41c271da (kx 2025-01-05 15:42:39 +0300 107) .BR ixchg(3),
41c271da (kx 2025-01-05 15:42:39 +0300 108) .BR icpy(3),
41c271da (kx 2025-01-05 15:42:39 +0300 109) .BR icvt(3),
41c271da (kx 2025-01-05 15:42:39 +0300 110) .BR imul(3),
41c271da (kx 2025-01-05 15:42:39 +0300 111) .BR ismul(3),
41c271da (kx 2025-01-05 15:42:39 +0300 112) .BR idiv(3),
41c271da (kx 2025-01-05 15:42:39 +0300 113) .BR isdiv(3),
41c271da (kx 2025-01-05 15:42:39 +0300 114) .BR iatoi(3),
41c271da (kx 2025-01-05 15:42:39 +0300 115) .BR iatoui(3).