<?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>MCUXpresso IDE中的主题 Re: uint16_t to unsigned char</title>
    <link>https://community.nxp.com/t5/MCUXpresso-IDE/uint16-t-to-unsigned-char/m-p/1003559#M5195</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your example, you are not converting anything: all what you do is to cast a pointer from (uint16_t*) to (uint8_t*).&lt;/P&gt;&lt;P&gt;So if you read from your casted pointer, you simply will read from the MSB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you want to read the lower 8bits of a 16bit, you simply can do someting like&lt;/P&gt;&lt;P&gt;uint8_t val8u;&lt;/P&gt;&lt;P&gt;uint16_val16u = 0x1234;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;val8u = val16u; // implicit cast, val8u will be assigned with 0x34;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want the upper bits:&lt;/P&gt;&lt;P&gt;val8u = (val16u&amp;gt;&amp;gt;8); // shift and implicit cast, val8u will have value 0x12&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 21 Dec 2019 10:33:42 GMT</pubDate>
    <dc:creator>ErichStyger</dc:creator>
    <dc:date>2019-12-21T10:33:42Z</dc:date>
    <item>
      <title>uint16_t to unsigned char</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/uint16-t-to-unsigned-char/m-p/1003558#M5194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, I tried to convert uint16_t to unsigned char. Make some search on internet and find some methods but didnt understand and not sure code will work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;header code:&lt;/P&gt;&lt;P&gt;typedef struct {&lt;BR /&gt; unsigned char *datax;&lt;BR /&gt; unsigned int size;&lt;BR /&gt; unsigned char *datay;&lt;BR /&gt;}message;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;main code:&lt;/P&gt;&lt;P&gt;uint16_t x,y;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* x and y get values by another function and ı am trying to do convert.*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;msg-&amp;gt;datax = ((unsigned char *)(&amp;amp;x));&lt;BR /&gt;msg-&amp;gt;datay = ((unsigned char *)(&amp;amp;y));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is the transform okey ? Is there any other way?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Dec 2019 12:41:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/uint16-t-to-unsigned-char/m-p/1003558#M5194</guid>
      <dc:creator>omerkaanbasakin</dc:creator>
      <dc:date>2019-12-19T12:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: uint16_t to unsigned char</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/uint16-t-to-unsigned-char/m-p/1003559#M5195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your example, you are not converting anything: all what you do is to cast a pointer from (uint16_t*) to (uint8_t*).&lt;/P&gt;&lt;P&gt;So if you read from your casted pointer, you simply will read from the MSB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you want to read the lower 8bits of a 16bit, you simply can do someting like&lt;/P&gt;&lt;P&gt;uint8_t val8u;&lt;/P&gt;&lt;P&gt;uint16_val16u = 0x1234;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;val8u = val16u; // implicit cast, val8u will be assigned with 0x34;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want the upper bits:&lt;/P&gt;&lt;P&gt;val8u = (val16u&amp;gt;&amp;gt;8); // shift and implicit cast, val8u will have value 0x12&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Dec 2019 10:33:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/uint16-t-to-unsigned-char/m-p/1003559#M5195</guid>
      <dc:creator>ErichStyger</dc:creator>
      <dc:date>2019-12-21T10:33:42Z</dc:date>
    </item>
  </channel>
</rss>

