<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic itoa() and uitoa() in Redlib in LPCXpresso IDE FAQs</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/itoa-and-uitoa-in-Redlib/m-p/470806#M71</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;&lt;STRONG&gt;itoa()&lt;/STRONG&gt; is non-standard library function which is provided in many other toolchains to convert an integer to a string. To ease porting, the LPCXpresso IDE provides two variants of this function in the Redlib C library....&lt;/P&gt;&lt;PRE style="font-family: monospace, courier; font-size: 1.1em; padding: 0.5em; background-color: #f0ece6;"&gt;char * itoa(int value, char *vstring, unsigned int base); 
char * uitoa(unsigned int value, char *vstring, unsigned int base);&lt;/PRE&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;which can be accessed via the system header....&lt;/P&gt;&lt;PRE style="font-family: monospace, courier; font-size: 1.1em; padding: 0.5em; background-color: #f0ece6;"&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/PRE&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;&lt;STRONG&gt;itoa()&lt;/STRONG&gt; converts an integer value to a null-terminated string using the specified base and stores the result in the array pointed to by the vstring parameter. base can take any value between 2 and 16; where 2 = binary, 8 = octal, 10 = decimal and 16 = hexidecimal.&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;If base is 10 and the value is negative, then the resulting string is preceded with a minus sign (-). With any other base, value is always considered unsigned.&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;The return value to the function is a pointer to the resulting null-terminated string, the same as parameter vstring.&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;&lt;STRONG&gt;uitoa()&lt;/STRONG&gt; is similar but treats the input value as unsigned in all cases.&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;Note that the caller is responsible for reserving space for the output character array - the recommended length is 33, which is long enough to contain any possible value regardless of the base used.&lt;/P&gt;&lt;H3 id="toc-hId-1511798288" style="font-family: Lato, sans-serif; color: #333333;"&gt;Example invocations&lt;/H3&gt;&lt;PRE style="font-family: monospace, courier; font-size: 1.1em; color: #646464; padding: 0.5em; background-color: #f0ece6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char vstring [33];
&amp;nbsp;&amp;nbsp;&amp;nbsp; itoa (value,vstring,10); // convert to decimal 
&lt;SPAN style="font-family: monospace, serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; itoa (value,vstring,16);&lt;/SPAN&gt;&lt;SPAN style="font-family: monospace, serif;"&gt; // convert to hexadecimal&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: monospace, serif;"&gt;itoa (value,vstring,8);&lt;/SPAN&gt;&lt;SPAN style="font-family: monospace, serif;"&gt;; // convert to octal&lt;/SPAN&gt;&lt;/PRE&gt;&lt;H2 id="toc-hId--843845168" style="font-family: Lato, sans-serif; color: #e66e08; font-size: 18px; background: 0 50% #ffffff;"&gt;Standards compliance&lt;/H2&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;As noted above, itoa() / uito() are not standard C library functions. A standard-compliant alternative for some cases may be to use sprintf():&lt;/P&gt;&lt;PRE style="font-family: monospace, courier; font-size: 1.1em; padding: 0.5em; background-color: #f0ece6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sprintf(vstring,"%d",value); // convert to decimal 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sprintf(vstring,"%x",value); // convert to hexadecimal 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sprintf(vstring,"%o",value); // convert to octal&lt;/PRE&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;&lt;STRONG&gt;NOTE : &lt;/STRONG&gt;The Newlib C library does not provide implementations of itoa() / uitoa().&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 Mar 2016 20:00:32 GMT</pubDate>
    <dc:creator>lpcware-support</dc:creator>
    <dc:date>2016-03-31T20:00:32Z</dc:date>
    <item>
      <title>itoa() and uitoa() in Redlib</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/itoa-and-uitoa-in-Redlib/m-p/470806#M71</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;&lt;STRONG&gt;itoa()&lt;/STRONG&gt; is non-standard library function which is provided in many other toolchains to convert an integer to a string. To ease porting, the LPCXpresso IDE provides two variants of this function in the Redlib C library....&lt;/P&gt;&lt;PRE style="font-family: monospace, courier; font-size: 1.1em; padding: 0.5em; background-color: #f0ece6;"&gt;char * itoa(int value, char *vstring, unsigned int base); 
char * uitoa(unsigned int value, char *vstring, unsigned int base);&lt;/PRE&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;which can be accessed via the system header....&lt;/P&gt;&lt;PRE style="font-family: monospace, courier; font-size: 1.1em; padding: 0.5em; background-color: #f0ece6;"&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/PRE&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;&lt;STRONG&gt;itoa()&lt;/STRONG&gt; converts an integer value to a null-terminated string using the specified base and stores the result in the array pointed to by the vstring parameter. base can take any value between 2 and 16; where 2 = binary, 8 = octal, 10 = decimal and 16 = hexidecimal.&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;If base is 10 and the value is negative, then the resulting string is preceded with a minus sign (-). With any other base, value is always considered unsigned.&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;The return value to the function is a pointer to the resulting null-terminated string, the same as parameter vstring.&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;&lt;STRONG&gt;uitoa()&lt;/STRONG&gt; is similar but treats the input value as unsigned in all cases.&lt;/P&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;Note that the caller is responsible for reserving space for the output character array - the recommended length is 33, which is long enough to contain any possible value regardless of the base used.&lt;/P&gt;&lt;H3 id="toc-hId-1511798288" style="font-family: Lato, sans-serif; color: #333333;"&gt;Example invocations&lt;/H3&gt;&lt;PRE style="font-family: monospace, courier; font-size: 1.1em; color: #646464; padding: 0.5em; background-color: #f0ece6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char vstring [33];
&amp;nbsp;&amp;nbsp;&amp;nbsp; itoa (value,vstring,10); // convert to decimal 
&lt;SPAN style="font-family: monospace, serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; itoa (value,vstring,16);&lt;/SPAN&gt;&lt;SPAN style="font-family: monospace, serif;"&gt; // convert to hexadecimal&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: monospace, serif;"&gt;itoa (value,vstring,8);&lt;/SPAN&gt;&lt;SPAN style="font-family: monospace, serif;"&gt;; // convert to octal&lt;/SPAN&gt;&lt;/PRE&gt;&lt;H2 id="toc-hId--843845168" style="font-family: Lato, sans-serif; color: #e66e08; font-size: 18px; background: 0 50% #ffffff;"&gt;Standards compliance&lt;/H2&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;As noted above, itoa() / uito() are not standard C library functions. A standard-compliant alternative for some cases may be to use sprintf():&lt;/P&gt;&lt;PRE style="font-family: monospace, courier; font-size: 1.1em; padding: 0.5em; background-color: #f0ece6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sprintf(vstring,"%d",value); // convert to decimal 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sprintf(vstring,"%x",value); // convert to hexadecimal 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sprintf(vstring,"%o",value); // convert to octal&lt;/PRE&gt;&lt;P style="color: #646464; font-family: Arial, sans-serif; font-size: 12px;"&gt;&lt;STRONG&gt;NOTE : &lt;/STRONG&gt;The Newlib C library does not provide implementations of itoa() / uitoa().&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Mar 2016 20:00:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/itoa-and-uitoa-in-Redlib/m-p/470806#M71</guid>
      <dc:creator>lpcware-support</dc:creator>
      <dc:date>2016-03-31T20:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: itoa() and uitoa() in Redlib</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/itoa-and-uitoa-in-Redlib/m-p/2007196#M232</link>
      <description>&lt;P&gt;The itoa() and uitoa() functions are non-standard, but provided in LPCXpresso's Redlib C library for converting integers to strings in different bases (e.g., decimal, hexadecimal, octal). While useful for porting, they are not part of the standard C library. An alternative is using sprintf() for standard compliance. Keep in mind, the caller must allocate sufficient space for the result, typically 33 characters.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 16:06:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/itoa-and-uitoa-in-Redlib/m-p/2007196#M232</guid>
      <dc:creator>manasaads</dc:creator>
      <dc:date>2024-12-04T16:06:12Z</dc:date>
    </item>
  </channel>
</rss>

