itoa question

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi:

I'm using itoa with an unsigned int, but itoa is handling itoa as a signed int :

uint16_t foo;
uint8_t str[10];

foo=32768;
itoa(foo,str,10);

The above code makes str="-32768" . Is this the normal behavior of itoa ? Shouldn't itoa handle foo as an unsigned integer ?

Using ltoa gives me the right answer.

Regards,
Alejandro.

admin's test signature
 

Last Edited: Thu. Jun 8, 2017 - 12:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope, see the
itoa() documentation.
It is documented to take an »int« which is a signed
data type.

Note that avr-libc also contains a function utoa()
which is probably what you want.

Folks, just read the docs...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi :

I read the doc, I just didn't understand it. I thought "integer value" mean "signed or unsigned". I completely miss the utoa(). Shame on me. I'll try harder next time :) .

Regards,
Alejandro.

admin's test signature
 

Topic locked