<?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 converting an string to a single variable... in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131675#M1585</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;I am having huge problem.&lt;/DIV&gt;&lt;DIV&gt;I am having some sort of weird problem when multiplying by 2^15.&lt;BR /&gt;My main goal is I want a subroutine that can take an array of 6 variables and concatinate them into 1 single float variable. ex:&lt;/DIV&gt;&lt;BLOCKQUOTE class="jive-quote" dir="ltr"&gt;&lt;DIV&gt;if I have&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;array[6] = {6,5,4,3,2,1};&lt;/DIV&gt;&lt;DIV&gt;I want to have a&amp;nbsp;double variable equal to "654321"&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;anyways...the way I tried to do it, is the following:&lt;/DIV&gt;&lt;BLOCKQUOTE class="jive-quote" dir="ltr"&gt;&lt;DIV&gt;var = array[0] * 100000 + array[1] * 10000 + array[2] * 1000 + array[3] * 100 + array[4] * 10 + array[5];&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;This is the only method I know to do this (as I'm a student working on my final year project learning all this!)&lt;BR /&gt;With this method, it works sometimes, but not if array[1] is &amp;gt; 3.&lt;/DIV&gt;&lt;DIV&gt;When array[1] is &amp;gt; 3 I start getting negative results that are all wrong!&lt;/DIV&gt;&lt;DIV&gt;What I figured out is that it has something to do with 2^15 (32768), which is why array[1] can not be &amp;gt; 3. i dont know why. But I did some testing doing the following: (all variables are doubles)&lt;/DIV&gt;&lt;BLOCKQUOTE class="jive-quote" dir="ltr"&gt;&lt;DIV&gt;void main(void) {&lt;BR /&gt;&amp;nbsp;x1 = 3 * 10000;&lt;BR /&gt;&amp;nbsp;x2 = 4 * 10000;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;x3 = 4 * 1000000;&lt;BR /&gt;&amp;nbsp;x4 = 3000 + 12767;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;x5 = 3000 + 12768;&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;when running this, I got the following results:&lt;BR /&gt;&amp;nbsp;x1 = 30000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----this is&amp;nbsp;what is expected&lt;BR /&gt;&amp;nbsp;x2 = -25536&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----this is&amp;nbsp;not what I want&lt;BR /&gt;&amp;nbsp;x3 = 4000000&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----I am not overflowing because I can multiply larger #'s&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;x4 = 32767&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----this is ok...but from here on is where the errors start&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;x4 = -32768&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----the sign flips, then it starts counting towards 0 as x goes up&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am using a licenced version of codewarrior with mc9s12e128 with 32-bit float variables enabled.&lt;BR /&gt;if anyone can see what i'm missing here, it would be greatly appreciated.&lt;BR /&gt;Or if anyone knows an alternate method to convert an array to a single variable, that would be great. I also need to do this vice versa, from a single varible split into an array, i've made code for that, but I get the same problem.&lt;/DIV&gt;&lt;DIV&gt;This problem ONLY occurs when the 2nd (0X0000) is &amp;gt; 3. All other variables work.&lt;/DIV&gt;&lt;DIV&gt;thanks if anyone can help,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mark&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Apr 2006 06:53:39 GMT</pubDate>
    <dc:creator>marcoB</dc:creator>
    <dc:date>2006-04-07T06:53:39Z</dc:date>
    <item>
      <title>converting an string to a single variable...</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131675#M1585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;I am having huge problem.&lt;/DIV&gt;&lt;DIV&gt;I am having some sort of weird problem when multiplying by 2^15.&lt;BR /&gt;My main goal is I want a subroutine that can take an array of 6 variables and concatinate them into 1 single float variable. ex:&lt;/DIV&gt;&lt;BLOCKQUOTE class="jive-quote" dir="ltr"&gt;&lt;DIV&gt;if I have&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;array[6] = {6,5,4,3,2,1};&lt;/DIV&gt;&lt;DIV&gt;I want to have a&amp;nbsp;double variable equal to "654321"&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;anyways...the way I tried to do it, is the following:&lt;/DIV&gt;&lt;BLOCKQUOTE class="jive-quote" dir="ltr"&gt;&lt;DIV&gt;var = array[0] * 100000 + array[1] * 10000 + array[2] * 1000 + array[3] * 100 + array[4] * 10 + array[5];&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;This is the only method I know to do this (as I'm a student working on my final year project learning all this!)&lt;BR /&gt;With this method, it works sometimes, but not if array[1] is &amp;gt; 3.&lt;/DIV&gt;&lt;DIV&gt;When array[1] is &amp;gt; 3 I start getting negative results that are all wrong!&lt;/DIV&gt;&lt;DIV&gt;What I figured out is that it has something to do with 2^15 (32768), which is why array[1] can not be &amp;gt; 3. i dont know why. But I did some testing doing the following: (all variables are doubles)&lt;/DIV&gt;&lt;BLOCKQUOTE class="jive-quote" dir="ltr"&gt;&lt;DIV&gt;void main(void) {&lt;BR /&gt;&amp;nbsp;x1 = 3 * 10000;&lt;BR /&gt;&amp;nbsp;x2 = 4 * 10000;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;x3 = 4 * 1000000;&lt;BR /&gt;&amp;nbsp;x4 = 3000 + 12767;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;x5 = 3000 + 12768;&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;when running this, I got the following results:&lt;BR /&gt;&amp;nbsp;x1 = 30000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----this is&amp;nbsp;what is expected&lt;BR /&gt;&amp;nbsp;x2 = -25536&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----this is&amp;nbsp;not what I want&lt;BR /&gt;&amp;nbsp;x3 = 4000000&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----I am not overflowing because I can multiply larger #'s&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;x4 = 32767&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----this is ok...but from here on is where the errors start&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;x4 = -32768&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;----the sign flips, then it starts counting towards 0 as x goes up&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am using a licenced version of codewarrior with mc9s12e128 with 32-bit float variables enabled.&lt;BR /&gt;if anyone can see what i'm missing here, it would be greatly appreciated.&lt;BR /&gt;Or if anyone knows an alternate method to convert an array to a single variable, that would be great. I also need to do this vice versa, from a single varible split into an array, i've made code for that, but I get the same problem.&lt;/DIV&gt;&lt;DIV&gt;This problem ONLY occurs when the 2nd (0X0000) is &amp;gt; 3. All other variables work.&lt;/DIV&gt;&lt;DIV&gt;thanks if anyone can help,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mark&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Apr 2006 06:53:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131675#M1585</guid>
      <dc:creator>marcoB</dc:creator>
      <dc:date>2006-04-07T06:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: converting an string to a single variable...</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131676#M1586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;What is the type of your array? signed int, signed long, unsigned?&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Apr 2006 09:06:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131676#M1586</guid>
      <dc:creator>gravity</dc:creator>
      <dc:date>2006-04-07T09:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: converting an string to a single variable...</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131677#M1587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;char&lt;/P&gt;&lt;P&gt;only decimals in the array&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Apr 2006 10:46:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131677#M1587</guid>
      <dc:creator>marcoB</dc:creator>
      <dc:date>2006-04-07T10:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: converting an string to a single variable...</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131678#M1588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;This worked in simulation. You need to type cast the char to a float. I also included a function to convert char array to float.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;float x1,x2,x3,x4,x5;&lt;/DIV&gt;&lt;DIV&gt;char array[6] = {6,5,4,3,2,1};&lt;/DIV&gt;&lt;DIV&gt;float MyNumber, Number;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Function to convert array of char to float */&lt;BR /&gt;float ArrayToFloat(char *ArrayPtr, int NumberOfElements){&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/* Local variables */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;float Multiplier = 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;float Number = 0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;int i;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/* Work backwards through array */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;for(i = NumberOfElements; i &amp;gt; 0; i--){&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Add in current digit */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Number += (float)ArrayPtr[i-1] * Multiplier;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Next decade */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Multiplier *= 10;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/* Return the converted value */&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;return Number;&lt;BR /&gt;}&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;void main(void) {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;x1 = (float)3 * 10000;&lt;BR /&gt;&amp;nbsp;x2 = (float)4 * 10000;&lt;BR /&gt;&amp;nbsp;x3 = (float)4 * 1000000;&lt;BR /&gt;&amp;nbsp;x4 = (float)3000 + 12767;&lt;BR /&gt;&amp;nbsp;x5 = (float)3000 + 12768;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;MyNumber = (float)array[0] * 100000;&lt;BR /&gt;&amp;nbsp;MyNumber += (float)array[1] * 10000;&lt;BR /&gt;&amp;nbsp;MyNumber += (float)array[2] * 1000;&lt;BR /&gt;&amp;nbsp;MyNumber += (float)array[3] * 100;&lt;BR /&gt;&amp;nbsp;MyNumber += (float)array[4] * 10;&lt;BR /&gt;&amp;nbsp;MyNumber += (float)array[5];&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;/* Convert using subroutine */&lt;BR /&gt;&amp;nbsp;Number = ArrayToFloat(&amp;amp;array[0], 6);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;for(;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt; {} /* wait forever */&lt;BR /&gt;}&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;Message Edited by Technoman64 on &lt;SPAN class="date_text"&gt;04-07-2006&lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;06:07 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Message Edited by Technoman64 on &lt;SPAN class="date_text"&gt;04-07-2006&lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;06:08 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Apr 2006 18:05:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131678#M1588</guid>
      <dc:creator>Technoman64</dc:creator>
      <dc:date>2006-04-07T18:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: converting an string to a single variable...</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131679#M1589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;thanks! The subroutine worked great. but the MyNumber variable didnt.&lt;BR /&gt;they look like they same operations too. for array[6] = {6,5,4,3,2,1};&lt;BR /&gt;number = 654321 which is great, but MyNumber = 601073.&lt;BR /&gt;also x4 and x4&amp;nbsp; were 15767 and 15768. Seems a little odd, but the subroutine works, so i'll work off that structure. thanks!&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Apr 2006 20:37:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131679#M1589</guid>
      <dc:creator>marcoB</dc:creator>
      <dc:date>2006-04-07T20:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: converting an string to a single variable...</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131680#M1590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Mark,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If the six numbers are all single digits, you could convert them to an array of ASCII digits (by adding &lt;FONT face="Courier New"&gt;'0'&lt;/FONT&gt; to each one), then using the library function &lt;FONT face="Courier New"&gt;atof()&lt;/FONT&gt; (in stdlib.h) to convert the array directly to a float.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The reason your original calculation doesn't work is that, in the absence of any type definition, &lt;FONT face="Courier New"&gt;var&lt;/FONT&gt; is a &lt;FONT face="Courier New"&gt;signed int&lt;/FONT&gt;, which for a 9S12, means that the maximum value is 32767. Any value that attempts to go above this will wrap around to a negative number.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;One solution to this is declare &lt;FONT face="Courier New"&gt;var&lt;/FONT&gt; (and &lt;FONT face="Courier New"&gt;x1&lt;/FONT&gt;-&lt;FONT face="Courier New"&gt;x5&lt;/FONT&gt;) as &lt;FONT face="Courier New"&gt;unsigned long&lt;/FONT&gt;, and to use casts in each calculation to ensure that values are not truncated. For example:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;unsigned long x1;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;x1 = (unsigned long) array[0] * 10000UL;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'd recommend this in preference to &lt;FONT face="Courier New"&gt;float&lt;/FONT&gt; casts, as these processors are not designed for floating points maths, and so the resulting code is likely to be far less efficient.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Also, if you aren't already doing so, it is good practise to give an explicit type to every single variable you declare, and to make them unsigned unless you actually need signed values.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Hope that helps.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Steve Melnikoff&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Apr 2006 15:36:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131680#M1590</guid>
      <dc:creator>sjmelnikoff</dc:creator>
      <dc:date>2006-04-10T15:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: converting an string to a single variable...</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131681#M1591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;sjmelnikoff wrote:&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;If the six numbers are all single digits, you could convert them to an array of ASCII digits (by adding &lt;FONT face="Courier New"&gt;'0'&lt;/FONT&gt; to each one), then using the library function &lt;FONT face="Courier New"&gt;atof()&lt;/FONT&gt; (in stdlib.h) to convert the array directly to a float.&lt;/DIV&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Forgot to mention that, if you do this, the last element of the array needs to contain zero (&lt;FONT face="Courier New"&gt;0&lt;/FONT&gt;, not &lt;FONT face="Courier New"&gt;'0'&lt;/FONT&gt;), indicating the end of the string.&lt;/P&gt;&lt;P&gt;Out of interest, where is your input data coming from? Is it a string to start with (as suggested by the title of the thread)?&lt;/P&gt;&lt;P&gt;Steve M.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Apr 2006 17:50:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131681#M1591</guid>
      <dc:creator>sjmelnikoff</dc:creator>
      <dc:date>2006-04-10T17:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: converting an string to a single variable...</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131682#M1592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;thanks...i got it all working now. works well.&lt;BR /&gt;This array is coming from a GPS device.&lt;BR /&gt;I'm filling up an array with ASCII GPS coordinates through SCI.&lt;/DIV&gt;&lt;DIV&gt;thanks,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mark&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Apr 2006 00:46:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/converting-an-string-to-a-single-variable/m-p/131682#M1592</guid>
      <dc:creator>marcoB</dc:creator>
      <dc:date>2006-04-14T00:46:55Z</dc:date>
    </item>
  </channel>
</rss>

