Keil Logo

Technical Support

On-Line Manuals

Cx51 User's Guide

Cx51 Introduction Compiling Programs Language Extensions Preprocessor Advanced Programming 8051 Derivatives Error Messages Library Reference Library Files Source Code Standard Types jmp_buf size_t va_list wchar_t Macros CBYTE CWORD DBYTE DWORD FARRAY FCARRAY FCVAR FVAR PBYTE PWORD XBYTE XWORD Routines By Category Buffer Manipulation Routines Character Routines Data Conversion Routines Intrinsic Routines Math Routines Memory Allocation Routines Stream I/O Routines String Routines Variable Length Argument Routines Miscellaneous Routines Include Files SFR Definitions 80c517.h absacc.h assert.h ctype.h float.h intrins.h limits.h math.h rtx51tny.h setjmp.h stdarg.h stddef.h stdio.h stdlib.h string.h Reference _chkfloat_ _crol_ _cror_ _getkey _irol_ _iror_ _lrol_ _lror_ _nop_ _pop_ _push_ _testbit_ _tolower _toupper abs acos acos517 asin asin517 assert atan atan2 atan517 atof atof517 atoi atol cabs calloc ceil cos cos517 cosh exp exp517 fabs floor fmod free getchar gets init_mempool isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit labs log log10 log10517 log517 longjmp malloc memccpy memchr memcmp memcpy memmove memset modf offsetof pow printf printf517 putchar puts rand realloc scanf scanf517 setjmp sin sin517 sinh sprintf sprintf517 sqrt sqrt517 srand sscanf sscanf517 strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strpos strrchr strrpbrk strrpos strspn strstr strtod strtod517 strtok strtol strtoul switchbank tan tan517 tanh toascii toint tolower toupper ungetchar va_arg va_end va_start vprintf vsprintf Appendix


#include <stdlib.h>

unsigned long strtoul (
  char *string,          /* string to convert */
  char **ptr,            /* ptr to subsequent characters */
  unsigned char base);   /* number base for conversion */

The strtoul function converts string into an unsigned long value. The input string is a sequence of characters that can be interpreted as an integer number. Whitespace characters at the beginning of string are skipped. An optional sign may precede the number.

The value of *ptr is set to point to the first character in string immediately following the converted part of string. If ptr is NULL, no value is assigned to *ptr. If no conversion is possible, *ptr is set to the value of string and the value 0 is returned by the strtol function.

If the base is zero, the syntax expected is similar to that of integer constants, which is formed by a succession of:

  • An optional prefix indicating octal ("0") or hexadecimal ("0x") base.
  • A sequence of decimal digits (if no base prefix was specified) or either octal or hexadecimal digits if a specific prefix is present.

The radix of the number is deduced from its format.

If the value of base is in the range 2-36, the number in string must consist of a non-zero sequence of letters and digits representing an integer in the specified base. The letters a-z (or A-Z) represent the values 10-36. Only those letters representing values less than the base are permitted. If the base is 16, the number may begin with 0x or 0X, which is ignored.

The strtol function requires string to have the following format:

whitespace〛 〚{+|-}〛 digits


whitespace May be any whitespace characters.
digits May be one or more decimal digits (0-9).
Return Value

The strtoul function returns the integer value that is produced by interpreting the characters in string as a number. The value ULONG_MAX is returned in case of overflow.

See Also

atof, atof517, atoi, atol, strtod, strtod517, strtol

#include <stdlib.h>
#include <stdio.h> /* for printf */

void tst_strtoul (void) {
  unsigned long ul;
  char s [] = "12345AB next";
  char *p;

  ul = strtoul (s, &p, 16);
  printf ("strtoul(%s) = %lx\n", s, ul);

/* p points to " next" */
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.