<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro 5 File system routines</title>
		<link>http://www.allegro.cc/forums/view/608601</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 16 Oct 2011 03:14:51 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi there, </p><p>I was reading the &quot;ex_dir&quot; example but there is something that I can&#39;t understand:</p><p><span class="source-code"><span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_fs_entry_mode"><span class="a">al_get_fs_entry_mode</span></a><span class="k2">(</span>entry<span class="k2">)</span> <span class="k3">&amp;</span> ALLEGRO_FILEMODE_ISDIR<span class="k2">)</span></span></p><p><span class="source-code">ALLEGRO_FILEMODE_ISDIR</span> is a simply <span class="source-code"><span class="k1">enum</span></span> type, since <span class="source-code">ALLEGRO_FILEMODE_ISDIR</span> is number 5 should contain the number 5. </p><p>I don&#39;t know how the Boolean operator <span class="source-code"><span class="k3">&amp;</span></span> works when it&#39;s alone, I guess that if some number is bigger than 1 would be true too, but I&#39;m not sure. </p><p>But what I can&#39;t really understand is that I went to the sources and found this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">typedef</span> <span class="k1">enum</span> <a href="http://www.allegro.cc/manual/ALLEGRO_FILE_MODE"><span class="a">ALLEGRO_FILE_MODE</span></a>
<span class="k2">{</span>
   ALLEGRO_FILEMODE_READ    <span class="k3">=</span> <span class="n">1</span>,
   ALLEGRO_FILEMODE_WRITE   <span class="k3">=</span> <span class="n">1</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="n">1</span>,
   ALLEGRO_FILEMODE_EXECUTE <span class="k3">=</span> <span class="n">1</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="n">2</span>,
   ALLEGRO_FILEMODE_HIDDEN  <span class="k3">=</span> <span class="n">1</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="n">3</span>,
   ALLEGRO_FILEMODE_ISFILE  <span class="k3">=</span> <span class="n">1</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="n">4</span>,
   ALLEGRO_FILEMODE_ISDIR   <span class="k3">=</span> <span class="n">1</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="n">5</span>,
<span class="k2">}</span> <a href="http://www.allegro.cc/manual/ALLEGRO_FILE_MODE"><span class="a">ALLEGRO_FILE_MODE</span></a><span class="k2">;</span>
</pre></div></div><p>

What are doing all those <span class="source-code"><span class="k3">&lt;</span><span class="k3">&lt;</span></span> there?, and BTW I don&#39;t even know what is the name of that symbol I can&#39;t search it in Google. I can&#39;t remember if the programming book I have talks about that symbol, besides the typical <span class="source-code">cout<span class="k3">&lt;</span><span class="k3">&lt;</span></span>.</p><p>Thanks!.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Sat, 15 Oct 2011 22:16:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The &#39;&lt;&lt;&#39; means shift left, similar to decimal multiplying by ten by moving all the digits leftward relative to the decimal point.</p><p>1 &lt;&lt; 0 = 1<br />1 &lt;&lt; 1 = 2<br />1 &lt;&lt; 2 = 4</p><p>it&#39;s easier and neater than</p><p>ALLEGRO_FILEMODE_ISFILE  = 16
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sat, 15 Oct 2011 22:26:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>TBH I generally prefer to just use plain hexadecimal notation for this stuff:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">typedef</span> <span class="k1">enum</span> <a href="http://www.allegro.cc/manual/ALLEGRO_FILE_MODE"><span class="a">ALLEGRO_FILE_MODE</span></a>
<span class="k2">{</span>
   ALLEGRO_FILEMODE_READ    <span class="k3">=</span> <span class="n">0x1</span>,   <span class="c">// 00000001b</span>
   ALLEGRO_FILEMODE_WRITE   <span class="k3">=</span> <span class="n">0x2</span>,   <span class="c">// 00000010b</span>
   ALLEGRO_FILEMODE_EXECUTE <span class="k3">=</span> <span class="n">0x4</span>,   <span class="c">// 00000100b</span>
   ALLEGRO_FILEMODE_HIDDEN  <span class="k3">=</span> <span class="n">0x8</span>,   <span class="c">// 00001000b</span>
   ALLEGRO_FILEMODE_ISFILE  <span class="k3">=</span> <span class="n">0x10</span>,  <span class="c">// 00010000b</span>
   ALLEGRO_FILEMODE_ISDIR   <span class="k3">=</span> <span class="n">0x20</span>   <span class="c">// 00100000b</span>
<span class="k2">}</span> <a href="http://www.allegro.cc/manual/ALLEGRO_FILE_MODE"><span class="a">ALLEGRO_FILE_MODE</span></a><span class="k2">;</span>
</pre></div></div><p>

Operator &amp; is a bitwise boolean operator, that is, it applies AND to each pair of bits. It&#39;s easy to see if you write the operands in binary. In <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_fs_entry_mode"><span class="a">al_get_fs_entry_mode</span></a><span class="k2">(</span>entry<span class="k2">)</span> <span class="k3">&amp;</span> ALLEGRO_FILEMODE_ISDIR</span>, it does this:</p><pre>
    XXXXXXXX
&amp;   00100000
-------------
    00X00000
</pre><p>

The result is all bits to 0, except the 6th least significant bit. If <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_fs_entry_mode"><span class="a">al_get_fs_entry_mode</span></a><span class="k2">(</span>entry<span class="k2">)</span></span> returns XX1XXXXX (the values of the X&#39;s don&#39;t matter since you&#39;re &quot;anding&quot; X and 0, which is always 0) the result of this operation will be 00100000 too, which evaluates to true. If it&#39;s XX0XXXXX the result will be 00000000, which evaluates to false. So effectivelly &amp; is used here to evaluate the n&#39;th bit.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Sat, 15 Oct 2011 23:07:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wow... Thank you Arthur I was able to find more info with the &quot;shift left&quot; words I was already answering you when I read the Oscar post. </p><p>But damn Oscar you&#39;re a <span class="cuss"><span>fuck</span></span>ing genius, with you and a little bit of cplusplus.com  I could understand completely what you&#39;re saying.</p><p>Since the unique way that <span class="source-code"><span class="k3">&amp;</span></span> returns 1 is when the operands (the actual bits) are 1, the unique number that it matters (in this case) is the 6th, from right to left, binaries need to be read from right to left?.</p><p>Another thing, you surely are using just 8 bits as an example, but in reality they&#39;re 32 aren&#39;t? something like:</p><pre>
if(
00000000 00000000 00000000 00<b>1</b>00000  // &lt;- al_get_fs_entry_mode(entry)
&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;
00000000 00000000 00000000 00<b>1</b>00000) // &lt;- ALLEGRO_FILEMODE_ISDIR

</pre><p>

Thank you man, very good explanation. Would you married me?. <img src="http://www.allegro.cc/forums/smileys/kiss.gif" alt=":-*" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Sun, 16 Oct 2011 00:02:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Storing flags this way is also useful because you can check multiple values</p><p><span class="source-code"><span class="k1">if</span> <span class="k2">(</span>flag <span class="k3">&amp;</span> <span class="k2">(</span>ALLEGRO_FILEMODE_HIDDEN <span class="k3">|</span> ALLEGRO_FILEMODE_ISDIR<span class="k2">)</span><span class="k2">)</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (l j)</author>
		<pubDate>Sun, 16 Oct 2011 03:14:51 +0000</pubDate>
	</item>
</rss>
