Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Usage of atoi and itoa in C language and addition and subtraction of integers exceeding long long int type variables
Usage of atoi and itoa in C language and addition and subtraction of integers exceeding long long int type variables

The calculation of large integers can be simplified through modular operations, or they can be read in as strings and then concatenated after segmented operations.

Attachment:

The sample codes for atoi and itoa are as follows:

#include

#include

void main( void )

{

char *s; int ix;

char buffer[20];< /p>

int i = 3445;

long l = -344115L;

unsigned long ul = 1234567890UL;

s = " -9885 pigs "; /* Test of atoi */

ix = atoi( s );

printf( "atoi test: ASCII string: %s\t\tinteger: %d\n ", s, ix );

_itoa( i, buffer, 10);

printf( "String of integer %d (radix 10): %s\n", i , buffer );

_itoa( i, buffer, 16 );

printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );

_itoa( i, buffer, 2 );

printf( "String of integer %d (radix 2): %s\n", i, buffer );< /p>

_ltoa( l, buffer, 16 );

printf( "String of long int %ld (radix 16): 0x%s\n", l,

< p> buffer );

_ultoa( ul, buffer, 16 );

printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul ,

buffer );

}

Output result:

atoi test: ASCII string: -9885 pigs integer: -9885< /p>

String of integer 3445 (radix 10): 3445

String of integer 3445 (radix 16): 0xd75

String of integer 3445 (radix 2): 110101110101

String of long int -344115 (radix 16): 0xfffabfcd

String of unsigned long 1234567890 (radix 16): 0x499602d2