<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>4 bytes ulong variable</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/14688/4-bytes-ulong-variable</link><description> Hi All,, 
 
I want to know a few alternate ways of doing the following thing. 
 
code unsigned long longconstant 0x1234; 
unsigned long longvariable; 
 
The &amp;#39;longvariable&amp;#39; gets its value one bit at a time. Suppose it is inside a for() loop and in each</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: 4 bytes ulong variable</title><link>https://community.arm.com/thread/38666?ContentTypeID=1</link><pubDate>Mon, 29 Apr 2002 07:28:47 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:97a1b186-120e-4f31-9917-9645f8a850d1</guid><dc:creator>Mark Odell</dc:creator><description>&lt;p&gt;Start with doing it the ISO C / Keil way:&lt;pre&gt;
const unsigned long code longconstant = 0x1234UL;
unsigned long      idata longvariable;&lt;/pre&gt;
The &amp;#39;code&amp;#39; Keil extension says, &amp;quot;Put it in with the program instructions&amp;quot; and the const tells the C compiler that no obvious writes to this variable will be allow at compile time. The &amp;#39;UL&amp;#39; suffix on the constant value tells the compiler it&amp;#39;s an unsigned long constant.&lt;br /&gt;
&lt;br /&gt;
Next a solution:&lt;pre&gt;
bit buildLongOneBitAtATimeAndCompare(void)
{
    const unsigned long code longConstant = 0x1234UL;
    unsigned long            longVariable;
    unsigned char            bitCount;

    longVariable  = 0;
    for (bitCount = 0; bitCount &amp;lt; 32; ++bitCount)
    {
          longVariable &amp;lt;&amp;lt;= 1;
          longVariable  |= r_port1_1;
    }

    return longConstant == longVariable;
}&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>