This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

instruction

Other Parts Discussed in Thread: MSP430G2553

is there any instruction like "  itoa();  " for msp430g2553 .

  • That is a C compiler question. Not an MSP430 question.

  • raju vadarevu1 said:
    is there any instruction like "  itoa();  " for msp430g2553 .

    Presence of 'standard' functions, as well as their implementation, depends on the compiler.

    On many systems, itoa is available because it is used by printf to print integers. However, for size reasons, it might be not there and you should use sprintf instead. IAR and CSS allow to limit the support level of (s)printf, so with limited support (no float) you won't get much overhead over a plain itoa function. Also, it is not officially part of the C standard library funciton set.

    Anyway, you can use this replacement

    	char * itoa(int value, char* str, int base) {
    		static char num[] = "0123456789abcdefghijklmnopqrstuvwxyz";
    		char* wstr=str, ret = str;
    		char aux;
    		int sign;
    		// Validate base
    		if (base<2 || base>35){ *wstr='\0'; return ret; }
    		// Take care of sign
    		if ((sign=value) < 0) value = -value;
    		// Conversion. Number is reversed.
    		do *wstr++ = num[value%base]; while(value/=base);
    		if(sign<0) *wstr++='-';
    		*wstr--='\0';
    		// Reverse string
    		while(wstr>str)
    			aux=*str, *wstr--=*str, *str++=aux;
    		return ret;
    	}
    
    

**Attention** This is a public forum