<?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 Returning a Hex value from an integer in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Returning-a-Hex-value-from-an-integer/m-p/159496#M4310</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using the 16 bit 9S12C128 MCU.&amp;nbsp; I&amp;nbsp;wrote this&amp;nbsp;simple code to return a hex value from an integer input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;word&amp;nbsp;dec_to_hex(signed short number)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; word hex_value;&lt;BR /&gt;&amp;nbsp; hex_value = number;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; return hex_value;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like to know is, does this return a 16 bit hex value (i.e. input = 32767, returns 0x7FFF; input = -32768, returns 0x8000)?&amp;nbsp; I can't really check the output because when I use "%d", I get an integer value; and when I use a "%x", I get the hex value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason for this is so that I can output the hex value to a DAC.&amp;nbsp; Also,&amp;nbsp;the data type&amp;nbsp;"word" in a 16 bit MCU means that one word is 16 bits and the data type "dword" means 32 bits?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have googled this but I could never get a clear answer.&amp;nbsp; Any help is appreciated.&amp;nbsp; Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 07 Mar 2009 05:32:44 GMT</pubDate>
    <dc:creator>DavidN_</dc:creator>
    <dc:date>2009-03-07T05:32:44Z</dc:date>
    <item>
      <title>Returning a Hex value from an integer</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Returning-a-Hex-value-from-an-integer/m-p/159496#M4310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using the 16 bit 9S12C128 MCU.&amp;nbsp; I&amp;nbsp;wrote this&amp;nbsp;simple code to return a hex value from an integer input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;word&amp;nbsp;dec_to_hex(signed short number)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; word hex_value;&lt;BR /&gt;&amp;nbsp; hex_value = number;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; return hex_value;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like to know is, does this return a 16 bit hex value (i.e. input = 32767, returns 0x7FFF; input = -32768, returns 0x8000)?&amp;nbsp; I can't really check the output because when I use "%d", I get an integer value; and when I use a "%x", I get the hex value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason for this is so that I can output the hex value to a DAC.&amp;nbsp; Also,&amp;nbsp;the data type&amp;nbsp;"word" in a 16 bit MCU means that one word is 16 bits and the data type "dword" means 32 bits?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have googled this but I could never get a clear answer.&amp;nbsp; Any help is appreciated.&amp;nbsp; Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Mar 2009 05:32:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Returning-a-Hex-value-from-an-integer/m-p/159496#M4310</guid>
      <dc:creator>DavidN_</dc:creator>
      <dc:date>2009-03-07T05:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a Hex value from an integer</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Returning-a-Hex-value-from-an-integer/m-p/159497#M4311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;It isn't clear whether "word" is defined as signed or unsigned integer. It is not an ISO C type, it is a non-standard type, so the answer can only be found in your compiler docs. What compiler are you using?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;My advise would generally be to avoid all untrusted integer types, including plain "int", "short" etc, and thereby avoid all signedness and porting issues. Use something like this instead:&lt;BR /&gt;&lt;BR /&gt;typedef unsigned char uint8;&lt;BR /&gt;typedef unsigned short uint16;&lt;BR /&gt;typedef unsigned long uint32;&lt;BR /&gt;typedef signed char sint8;&lt;BR /&gt;typedef signed short sint16;&lt;BR /&gt;typedef signed long sint32;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Mar 2009 15:30:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Returning-a-Hex-value-from-an-integer/m-p/159497#M4311</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2009-03-09T15:30:26Z</dc:date>
    </item>
  </channel>
</rss>

