<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eoin Griffin &#187; Java</title>
	<atom:link href="http://www.eoingriffin.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eoingriffin.com</link>
	<description>Web/Multimedia Design &#38; Development Portfolio</description>
	<lastBuildDate>Thu, 18 Mar 2010 05:04:27 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Useful hints: #1 &#8211; Odd/Even numbers (Modulo operator [%] and Bitwise And [&amp;])</title>
		<link>http://www.eoingriffin.com/code-hints/useful-hints-1-oddeven-numbers-modulo-operator/</link>
		<comments>http://www.eoingriffin.com/code-hints/useful-hints-1-oddeven-numbers-modulo-operator/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 19:21:50 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code hints]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[modulo]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.eoingriffin.com/?p=212</guid>
		<description><![CDATA[I&#8217;m going to start posting some useful little bits of code up here as i think of them.
This is partly to help with my exceptionally poor memory, and partly to help out anyone who might be interested. I encourage anyone else who knows of some similar little helpful tips to send them to me and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to start posting some useful little bits of code up here as i think of them.<br />
This is partly to help with my exceptionally poor memory, and partly to help out anyone who might be interested. I encourage anyone else who knows of some similar little helpful tips to send them to me and i&#8217;ll post them up here.</p>
<p>Ok, so here&#8217;s a nice simple one to start off. What&#8217;s an easy and simple method to determine if a number is odd or even?<br />
The answer lies with the modulo operator (%) or the bitwise AND operator (&#038;).</p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">i<span style="color: #000066; font-weight: bold;">%</span>2</div></td></tr></tbody></table></div>
<p>Whatever <strong>i</strong> is, <strong>i%2</strong> will evaluate to either 0 or 1.<br />
Or a faster method for determining odd or even numbers would be the Bitwise AND operator (represented by a single ampersand: &#038;):</p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">i<span style="color: #000066; font-weight: bold;">&amp;</span><span style="color: #000000; font-weight:bold;">1</span></div></td></tr></tbody></table></div>
<p>So what use is this?<br />
<span id="more-212"></span><br />
Let&#8217;s say you&#8217;ve got a for loop:</p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">%</span>2<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">// Or i&amp;1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//do something for odd numbers</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//do something else for even numbers</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>So why would we use the modulo operator if a bitwise AND is faster?<br />
To take this further, you could specify separate code for every nth number:</p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">switch</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">%</span>4<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">case</span> 0<span style="color: #000066; font-weight: bold;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;run every 4 iterations starting from 0&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">case</span> 1<span style="color: #000066; font-weight: bold;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;run every 4 iterations starting from 1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">case</span> 2<span style="color: #000066; font-weight: bold;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;run every 4 iterations starting from 2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">case</span> 3<span style="color: #000066; font-weight: bold;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;run every 4 iterations starting from 3&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>]]></content:encoded>
			<wfw:commentRss>http://www.eoingriffin.com/code-hints/useful-hints-1-oddeven-numbers-modulo-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flock</title>
		<link>http://www.eoingriffin.com/portfolio/flock/</link>
		<comments>http://www.eoingriffin.com/portfolio/flock/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 02:10:26 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Camera Tracking]]></category>
		<category><![CDATA[Installation]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://www.eoingriffin.com/?p=68</guid>
		<description><![CDATA[Flock is an interactive media installation created in 2008 by myself (Eoin Griffin), Gerard Mangan and Catherine Philpott. The aim of Flock was to create an interactive environment in a public space that would encourage social interaction between members of the public, particularly strangers that wouldn&#8217;t ordinarily interact.

Using camera tracking software, artificial intelligence to simulate the [...]]]></description>
			<content:encoded><![CDATA[<p>Flock is an interactive media installation created in 2008 by myself (Eoin Griffin), Gerard Mangan and Catherine Philpott. The aim of Flock was to create an interactive environment in a public space that would encourage social interaction between members of the public, particularly strangers that wouldn&#8217;t ordinarily interact.</p>
<div id="attachment_90" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-90" title="Flock visual prototype" src="http://www.eoingriffin.com/wp-content/uploads/2010/01/flock-e1264299497822.jpg" alt="Flock visual prototype" width="500" height="199" /><p class="wp-caption-text">Flock visual prototype</p></div>
<p><span id="more-68"></span><br />

<div class="ngg-galleryoverview" id="ngg-gallery-3-68">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-25" class="ngg-gallery-thumbnail-box" style="width:25%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.eoingriffin.com/wp-content/gallery/flock/img_4006.jpg" title="Flock hardware setup (hidden from prying eyes), contains 1x Apple Mac G4, 1x Sony PD-150 DVCam, 1x projector, 1x Mirror (to bounce the image to the ground), lots of wood, nails &amp; patience" class="thickbox" rel="set_3" >
								<img title="Flock hardware setup (hidden from prying eyes), contains 1x Apple Mac G4, 1x Sony PD-150 DVCam, 1x projector, 1x Mirror (to bounce the image to the ground), lots of wood, nails &amp; patience" alt="Flock hardware setup (hidden from prying eyes), contains 1x Apple Mac G4, 1x Sony PD-150 DVCam, 1x projector, 1x Mirror (to bounce the image to the ground), lots of wood, nails &amp; patience" src="http://www.eoingriffin.com/wp-content/gallery/flock/thumbs/thumbs_img_4006.jpg" width="66" height="100" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-26" class="ngg-gallery-thumbnail-box" style="width:25%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.eoingriffin.com/wp-content/gallery/flock/img_4010.jpg" title="Flock in action" class="thickbox" rel="set_3" >
								<img title="Flock in action" alt="Flock in action" src="http://www.eoingriffin.com/wp-content/gallery/flock/thumbs/thumbs_img_4010.jpg" width="100" height="55" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-27" class="ngg-gallery-thumbnail-box" style="width:25%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.eoingriffin.com/wp-content/gallery/flock/flock.jpg" title="Flock visual prototype" class="thickbox" rel="set_3" >
								<img title="Flock visual prototype" alt="Flock visual prototype" src="http://www.eoingriffin.com/wp-content/gallery/flock/thumbs/thumbs_flock.jpg" width="100" height="96" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>

</p>
<p>Using camera tracking software, artificial intelligence to simulate the movement of a flock of birds, a webcam, a projector and an artfully created, sturdy frame to house the entire apparatus (thanks Ger!), we were able to successfully complete the tasks we set ourselves for this project.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/zrXuxDhvgEM&amp;hl=en_GB&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/zrXuxDhvgEM&amp;hl=en_GB&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<h2>Credits:</h2>
<p><em>Project Manager:</em> Gerard Mangan</p>
<p><em>Design &amp; planning:</em> Catherine Philpott, <a href="http://www.eoingriffin.com/author/admin/">Eoin Griffin</a>, Gerard Mangan</p>
<p><em>Coding &amp; software implementation:</em> <a href="http://www.eoingriffin.com/author/admin/">Eoin Griffin</a> (Created using <a href="http://processing.org/">Processing (Java)</a> )</p>
<p><em>Hardware design &amp; planning:</em> Gerard Mangan<a href="http://processing.org/"></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.eoingriffin.com/portfolio/flock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
