Forum: Mikrocontroller und Digitale Elektronik AVR32 ulong -> string


von vdx (Gast)


Lesenswert?

Hi,
Gibt es für AVR32 irgendwo eine Funktion, die mir unsigned long in einen 
string verwandelt? Und wie binde ich das ein, wenn es sowas geht?
Danke schonmal für eure Hilfe

von Henry P. (henrylexx)


Lesenswert?


von Georg G. (df2au)


Lesenswert?

(aus dem Hilfe-File der AVR-LIBC)

char *   ultoa (unsigned long int __val, char *__s, int __radix)



Convert an unsigned long integer to a string.

The function ultoa() converts the unsigned long integer value from val 
into an ASCII representation that will be stored under s. The caller is 
responsible for providing sufficient storage in s.

Note:
    The minimal size of the buffer s depends on the choice of radix. For 
example, if the radix is 2 (binary), you need to supply a buffer with a 
minimal length of 8 * sizeof (unsigned long int) + 1 characters, i.e. 
one character for each bit plus one for the string terminator. Using a 
larger radix will require a smaller minimal buffer size.

Warning:
    If the buffer is too small, you risk a buffer overflow.

Conversion is done using the radix as base, which may be a number 
between 2 (binary conversion) and up to 36. If radix is greater than 10, 
the next digit after '9' will be the letter 'a'.

The ultoa() function returns the pointer passed as s.

von Bernhard S. (b_spitzer)


Lesenswert?

char Buffer[11];  // unsigned long bis 4,2 Milliarden, also max.
                  // 10 Stellen + 0-Terminierung des Strings
unsigned long Zahl=123456789;
sprintf(Buffer,"%ld",Zahl); // das kleine l ist wichtig!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.