<?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 Re: Missunderstanding code example (big/little endian, cast??) in LPCXpresso IDE</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534791#M4282</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Thu Jan 24 06:57:56 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: magicdim&lt;/STRONG&gt;&lt;BR /&gt;Ok, I think I understand... shifting 4 bits to FIOPIN register (LPC_GPIO0-&amp;gt;FIOPIN &amp;gt;&amp;gt; 4) results in pushing its bit number 3 at the end (number 0), and ANDing this result with 0x01 gives the state of this bit number 3 (pin P0.4 in this case)&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No, P0.4 is bit number 5 = 0b10000 :eek:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Right shifting 4 positions is moving this bit from position 4 (value:2^4) to 0 (value:2^0) =&amp;nbsp; 0b00001 :p&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 21:53:06 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T21:53:06Z</dc:date>
    <item>
      <title>Missunderstanding code example (big/little endian, cast??)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534786#M4277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by magicdim on Thu Jan 24 03:28:12 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;HI everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'am using LPCXpresso1769 board, and I would like to know if someone could explain the next pieces of code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the example "LPCX176x_cmsis2_systick" given in the IDE, we can find in leds.c:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
// Function to invert current state of LED2 [COLOR=Red](soldered on P0.22)[/COLOR]
void led2_invert (void)
{
int ledstate;

// Read current state of GPIO P0_0..31, which includes LED2
ledstate = LPC_GPIO0-&amp;gt;FIOPIN;
// Turn off LED2 if it is on
// (ANDing to ensure we only affect the LED output)
LPC_GPIO0-&amp;gt;FIOCLR = ledstate &amp;amp; (1 &amp;lt;&amp;lt; 22);
// Turn on LED2 if it is off
// (ANDing to ensure we only affect the LED output) dimitri
LPC_GPIO0-&amp;gt;FIOSET = ((~ledstate) &amp;amp; (1 &amp;lt;&amp;lt; 22));
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;ledstate = LPC_GPIO0-&amp;gt;FIOPIN;[COLOR=red]==&amp;gt;reads the states of P0 to P31, OK?[/COLOR]&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;LPC_GPIO0-&amp;gt;FIOCLR = ledstate &amp;amp; (1 &amp;lt;&amp;lt; 22);[COLOR=red] ==&amp;gt; sets 0 to P0.22, OK?[/COLOR]&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[COLOR=red]So we can assume that FIOPIN in the order 31....0 as we shift &amp;lt;&amp;lt; from right to left, OK?[/COLOR]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I see in Embedded Artists "demo" application:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
uint_8t btn1;
...
btn1 = ((GPIO_ReadValue(0) &amp;gt;&amp;gt; 4) &amp;amp; 0x01); [COLOR=Red]assumed to read P0.4...[/COLOR]&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;uint32_t GPIO_ReadValue(uint8_t portNum)
{
LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);

if (pGPIO != NULL) {
return pGPIO-&amp;gt;FIOPIN;
}

return (0);
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;static LPC_GPIO_TypeDef *GPIO_GetPointer(uint8_t portNum)
{
LPC_GPIO_TypeDef *pGPIO = NULL;

switch (portNum) {
case 0:
pGPIO = LPC_GPIO0;
break;
......
}

return pGPIO;
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So if I understand, GPIO_ReadValue(0) points to LPC_GPIO0-&amp;gt;FIOPIN,[COLOR=Red] OK?[/COLOR]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Which I don't understand is (GPIO_ReadValue(0) &amp;gt;&amp;gt; 4) ==&amp;gt; if we point to the base adresse of FIOPIN why do we shit from left to right???&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:53:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534786#M4277</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Missunderstanding code example (big/little endian, cast??)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534787#M4278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Thu Jan 24 03:43:58 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: magicdim&lt;/STRONG&gt;&lt;BR /&gt;.. why do we [COLOR=Red]shit[/COLOR] from left to right???&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;:eek:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please don't sh.. here at all :rolleyes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Right shift is used here to AND bit 4 with 0x01, so the result (btn1) is 0 or 1 ;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And yes, this registers are 32-bit, so you can shift them from 0-31 :)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:53:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534787#M4278</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: Missunderstanding code example (big/little endian, cast??)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534788#M4279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by magicdim on Thu Jan 24 04:41:51 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Woops, sorry for this typing error! &lt;SPAN class="lia-unicode-emoji" title=":face_with_open_mouth:"&gt;&lt;LI-EMOJI id="lia_face-with-open-mouth" title=":face_with_open_mouth:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for answering Zero.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you (or someone else!) explain to me what is the difference between:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;LPC_GPIO0-&amp;gt;FIOPIN &amp;amp; (1&amp;lt;&amp;lt;22)&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;(ANDING FIOPIN with 10000000000000000000000 right?, so FIOPIN is in the order 31-&amp;gt;0 and not 0-&amp;gt;31??)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and &lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;LPC_GPIO0-&amp;gt;FIOPIN &amp;gt;&amp;gt; 4 &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;(we are pointing to bit 0 of FIOPIN is it correct? so how can we shift 4 bits to the right???)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:53:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534788#M4279</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Missunderstanding code example (big/little endian, cast??)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534789#M4280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Thu Jan 24 05:34:52 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: magicdim&lt;/STRONG&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;LPC_GPIO0-&amp;gt;FIOPIN &amp;amp; (1&amp;lt;&amp;lt;22)&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;(ANDING FIOPIN with 10000000000000000000000 right?, so FIOPIN is in the order 31-&amp;gt;0 and not 0-&amp;gt;31??)&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No, you are ANDing 0b10000000000000000000000 &lt;SPAN class="lia-unicode-emoji" title=":winking_face:"&gt;&lt;LI-EMOJI id="lia_winking-face" title=":winking_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt; Result is either (1&amp;lt;&amp;lt;22) or (0&amp;lt;&amp;lt;22) :eek:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;LPC_GPIO0-&amp;gt;FIOPIN is an uint32_t (see LPC17xx.h), what's not clear there?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: magicdim&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;LPC_GPIO0-&amp;gt;FIOPIN &amp;gt;&amp;gt; 4 &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;(we are pointing to bit 0 of FIOPIN is it correct? so how can we shift 4 bits to the right???)&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No, you are right shifting (4 bits) a 32bit register, the result is still a 32 bit register &lt;SPAN class="lia-unicode-emoji" title=":face_with_tongue:"&gt;&lt;LI-EMOJI id="lia_face-with-tongue" title=":face_with_tongue:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:53:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534789#M4280</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Missunderstanding code example (big/little endian, cast??)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534790#M4281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by magicdim on Thu Jan 24 06:19:51 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Zero&lt;/STRONG&gt;&lt;BR /&gt;No, you are ANDing 0b10000000000000000000000 ;) Result is either (1&amp;lt;&amp;lt;22) or (0&amp;lt;&amp;lt;22) :eek:&lt;BR /&gt;&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIOPIN is an uint32_t (see LPC17xx.h), what's not clear there?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, I agree, this one wasn't my main issue, I was disturbed by the following...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Zero&lt;/STRONG&gt;&lt;BR /&gt;No, you are right shifting (4 bits) a 32bit register, the result is still a 32 bit register :p&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok, I think I understand... shifting 4 bits to FIOPIN register (LPC_GPIO0-&amp;gt;FIOPIN &amp;gt;&amp;gt; 4) results in pushing its bit number 3 at the end (number 0), and ANDing this result with 0x01 gives the state of this bit number 3 (pin P0.4 in this case)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I right??&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;P.S: sorry for my inaccurate writings...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:53:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534790#M4281</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Missunderstanding code example (big/little endian, cast??)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534791#M4282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Thu Jan 24 06:57:56 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: magicdim&lt;/STRONG&gt;&lt;BR /&gt;Ok, I think I understand... shifting 4 bits to FIOPIN register (LPC_GPIO0-&amp;gt;FIOPIN &amp;gt;&amp;gt; 4) results in pushing its bit number 3 at the end (number 0), and ANDing this result with 0x01 gives the state of this bit number 3 (pin P0.4 in this case)&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No, P0.4 is bit number 5 = 0b10000 :eek:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Right shifting 4 positions is moving this bit from position 4 (value:2^4) to 0 (value:2^0) =&amp;nbsp; 0b00001 :p&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:53:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534791#M4282</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Missunderstanding code example (big/little endian, cast??)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534792#M4283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by magicdim on Thu Jan 24 08:23:29 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;OK, thanks very much Zero, I understand! &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I posted my last reply a bit too fast before explaining what I understood!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help!! :)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 21:53:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Missunderstanding-code-example-big-little-endian-cast/m-p/534792#M4283</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T21:53:07Z</dc:date>
    </item>
  </channel>
</rss>

