<?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>Nicola Bortignon</title>
	<atom:link href="http://www.nicolabortignon.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.nicolabortignon.com</link>
	<description>A Developer&#039;s Life</description>
	<lastBuildDate>Thu, 05 Aug 2010 08:04:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Gone in 15 seconds Contest &#8211; Chapter I</title>
		<link>http://www.nicolabortignon.com/?p=39</link>
		<comments>http://www.nicolabortignon.com/?p=39#comments</comments>
		<pubDate>Sat, 24 Jul 2010 14:38:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://localhost:8888/wordpress4/?p=39</guid>
		<description><![CDATA[Introduction: Summer evenings may be so borings, we all know the &#8220;lazy dog layed on sofa&#8221; habit takes over! So why not gettin involved into an as3 contest? Contest&#8217;s name comes from the well know trash-movie, with a lower time limit (15seconds is the time before flash player goes in timeout). So, what are you [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><img class="alignleft" style="float: left; margin: 0 5px 0 0;" src="http://www.nicolabortignon.com/external_file/gone15secs.png" alt="Gone in 15 sec" /></p>
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;"><strong>Introduction:</strong></p>
<p>Summer evenings may be so borings, we all know the &#8220;lazy dog layed on sofa&#8221; habit takes over! So why not gettin involved into an as3 contest?<br />
Contest&#8217;s name comes from the well know trash-movie, with a lower time limit (15seconds is the time before flash player goes in timeout).</p>
<p>So, what are you suppose to do? Write code that  solve the following problem in less than 15seconds.<br />
Well, the main aim of the contest is to reach the lowest time, the upperbound limit is just to let you know that a brutal force approach will not work this time!</p>
<p><span id="more-39"></span><br />
<strong>Updates:</strong></p>
<p>Deadline moved to 16th August</p>
<p><strong>Goals of the contest:</strong></p>
<p>1.Share knowledge<br />
2.Recognize math as still a key skill, even on the daily work (i&#8217;ll come back on this as much as i can)<br />
3.Get a chance to try a &#8220;think-before-code&#8221; approach to a complex problem.<br />
4.Spend, I hope happy, hours on Optimizations, Data Structures and Algorithm complexity Topics.</p>
<p><strong>Contest topic:</strong></p>
<p>In math, as in Science in general, there are some still not solved problems.This means that we can&#8217;t give an answer to a particular question.<br />
One of this problems comes from Lothar Collatz. His conjecture asks if for every n (with n an integer number) the iteration</p>
<p><span class="smile"><img class="aligncenter" src="http://www.nicolabortignon.com/external_file/NumberedEquation1-1.gif" alt="Gone in 15 sec" /></span></p>
<p>always returns to 1. Actually this is formally undecidable even if there was (and still there is) a high number of mathematic minds that keep trying to give the problem an answer.<br />
For your luck, this is not the contest&#8217;s task.</p>
<p><strong>Contest task:</strong></p>
<p>Using the Collatz rule, and starting for ie with 11, we generate the following sequence:</p>
<p><em>11 -&gt; 34 -&gt; 17 -&gt; 52 -&gt; 26 -&gt; 13 -&gt; 40 -&gt; 20 -&gt; 10 -&gt; 5 -&gt; 16 -&gt; 8 -&gt; 4 -&gt; 2 -&gt; 1</em></p>
<p>we can call this a chain of 15 steps that leads to 1.</p>
<p>Write a function</p>
<pre class="brush:as3">collatz(upperBound:Number):Number</pre>
<p>returned value i need the number N < upperBound that produces the longest chain between all the numbers from 1 to upperBound.</p>
<p><strong>Submissions Testing:</p>
<p>Every submission will test with <a href="http://www.gskinner.com/blog/archives/2010/02/performancetest.html">Grant Skinner Performance Test v.2</a></p>
<p>There will be just a call to the funzion like collatz(n) where n will be a secret number (between 5 and 11 millions). The reason why this number will keep secret till the end of the contest is to avoid specific assumptions (that are in somehow possible, knowing the starting number).<br />
The test will run on a MacBookPro 2006 (2.3ghz &#8211; 2gb ram), on flash player (regular not debugger version) 10.1.53.64</p>
<p>With daily upgrade, i&#8217;ll publish the results from submitters, like this way:  nicolabortignon &#8211; 14.999ms. Top five positions will not display the timing, this means that all the top 5 positions timing is &lt; than 6th. Top 5 positions will not order, so we will know the winner (and top 3) only at the end of the contest. I hope this push you to keep searching for a better solution even if you are on top.<br />
I warmly suggest you not to share the entire submitted code, since the contest will be close; i really like instead to see you discussing (here on comments or wherever you prefear) about the work in progress so feel free to exchange suggestions.</p>
<p><strong>Sumbissions Rules</strong> (inspired by mikechambers):</p>
<ol>
<li>Code must be sended to (<em>info[at]nicolabortignon .com</em>) by 24:00, PST, Sunday, August <del datetime="2010-08-05T05:43:25+00:00">8th.</del> 16th</li>
<li>Code must be written in ActionScript 3.</li>
<li>All .as file must including the Name and contact information from the author.</li>
<li>Code must be release under an <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a> (includer on the header of the main .as file)</li>
<li>Try to comment out as much clear as you can the code</li>
<li>If the value returned from the function is wrong, submission will not get in consideration</li>
<li>Code that dosn&#8217;t compile will automaticly exclude the author from the contest  (so pls double check if it compiles before sending).</li>
<li>Code must authoring on Flash CS3 or aboves (Flex dependency will not allow).</li>
<li>External Libraries included in the code must be attached to the submission.</li>
<li>Code cannot require any additional tools, pre or post processing steps.</li>
<li>Code will publish at the end of the contest.</li>
<li>Devs may submit more than once and less than 5 times (this should let you change your mind on the approach, but not too many times).</li>
</ol>
<p><strong>Suggestions:</strong></p>
<p>As said, brutal force is not a competitive solution, btw you can start from that (setting your player timeout over 15s)<br />
Many papers, documents, even books, were written on this topic, usually some of them suggest algorithms to solve the problem. Try to use this resources in the right way, not paste and copy: i&#8217;m quite sure that lots of submitted proposal will more optimized that the general algorithms proposed in that references. So i can say that a thief approach will not put you on top.</p>
<p>Finally keep in mind that we don&#8217;t need the most elegant code, we just need the fastest <span class="smile"><img id="smile" src='http://www.nicolabortignon.com/wp-content/plugins/tango-smileys-extended/tango/smile.png' alt='Smile' title='Smile' class='tse-smiley' /></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nicolabortignon.com/?feed=rss2&amp;p=39</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Converter: Free Mp3 Encoder (aka Aiff / Wav to Mp3 conversion with AIR )</title>
		<link>http://www.nicolabortignon.com/?p=35</link>
		<comments>http://www.nicolabortignon.com/?p=35#comments</comments>
		<pubDate>Fri, 23 Jul 2010 21:54:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://localhost:8888/wordpress4/?p=35</guid>
		<description><![CDATA[Simplicity is about subtracting the obvious, and adding the meaningful. With this aphorism in mind i decide to realize this simple application. The main problem comes out from all my producers friends, they always sent me aiff file when they need to let me listen something, that is very frustrating moving 60mb for a 5 [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><strong>Simplicity is about subtracting the obvious, and adding the meaningful.</strong></p>
<p style="text-align: center;"><img src="http://www.nicolabortignon.com/wp-content/uploads/logoBlog.jpg" alt="Logo Converter" /></p>
<p>With this aphorism in mind i decide to realize this simple application. The main problem comes out from all my producers friends, they always sent me aiff file when they need to let me listen something, that is very frustrating moving 60mb for a 5 minutes song.</p>
<p>I always had in mind to try this out, and with advent of Air 2.0 and Native Process, i had finally the chance to realize this.<br />
(like usual someone did it before me .. so i must quote Thibault that basically use the same strategy on <a href="http://www.bytearray.org/?p=1142">AS3 Lame Project</a>.</p>
<p>Not going to much in depth, what i just do is calling the command line version of lame converter passing as parameter the kbps and path of the file i want to convert (or to be correct &#8220;encode&#8221; or &#8220;re-encode&#8221; in case the source file is an mp3 too)</p>
<p>Now let&#8217;z go straight to <strong>HOW TO USE IT</strong>:<br />
<span id="more-35"></span><br />
-  Download <a href="http://get.adobe.com/air/">latest version of adobe AIR </a><br />
- Install Adobe Air ( it will takes only few seconds, and for those who don&#8217;t know what air this, consider this installation not far different from the .NET framework any window user are used to)<br />
- Download version  according to your os of the converter:  <a href="http://www.nicolabortignon.com/APPconverter/Converter.dmg">DMG FOR MAC</a> , EXE FOR WINDOWS (comes shortly, just need to recompile the native installer on a window machine)<br />
- Install the converter<br />
- Enjoy</p>
<p>Following few screenshots:<br />
<a href="http://www.nicolabortignon.com/wp-content/uploads/01_big-1024x620.jpg"><img class="aligncenter size-large wp-image-71" title="01_big" src="http://www.nicolabortignon.com/wp-content/uploads/01_big-300x181.jpg" alt="" /></a></p>
<p>As you can see, program running gui is not intrusive, you can keep above any software without problems.</p>
<p><a href="http://www.nicolabortignon.com/wp-content/uploads/02_big-1024x620.jpg"><img class="aligncenter size-large wp-image-71" title="01_big" src="http://www.nicolabortignon.com/wp-content/uploads/02_big-300x181.jpg" alt="" /></a></p>
<p>Just press the O logo (o stands for Open .. smart isn&#8217;t it ?! ) and you will prompt with the &#8220;choose file&#8221; window</p>
<p><a href="http://www.nicolabortignon.com/wp-content/uploads/04_big-1024x620.jpg"><img class="aligncenter size-large wp-image-71" title="01_big" src="http://www.nicolabortignon.com/wp-content/uploads/04_big-300x181.jpg" alt="" /></a></p>
<p>You can easily change bitrate of encoding by right-click the icon on dock (or system tray on window)</p>
<p><a href="http://www.nicolabortignon.com/wp-content/uploads/03_big-1024x620.jpg"><img class="aligncenter size-large wp-image-71" title="01_big" src="http://www.nicolabortignon.com/wp-content/uploads/03_big-300x181.jpg" alt="" /></a></p>
<p>After choosing file, the gui expands to let you know the progress of the conversion. Just press the C logo (c stand for conversion) and &#8230;</p>
<p><a href="http://www.nicolabortignon.com/wp-content/uploads/05_big-1024x620.jpg"><img class="aligncenter size-large wp-image-71" title="01_big" src="http://www.nicolabortignon.com/wp-content/uploads/05_big-300x181.jpg" alt="" /></a></p>
<p>.. conversion starts .. should takes few seconds even if it&#8217;s pretty fast (circa 40 seconds for a 4 minutes aiff on my quad), converted files are saved on desktop with a -converted suffix</p>
<p><strong>Special tnx goes to:</strong></p>
<p><a href="http://lame.sourceforge.net/"> The lame Project </a><br />
<a href="http://myspace.com/siwelldj"> Siwell (Producer) </a> now he should stop sending me Aiff big files.. no excuses<br />
<a href="http://www.ableton.com/">Ableton Live</a> Keep produce great software folks!<br />
<strong>Future upgrade:</strong><br />
Even if this is a one-day project, i would like to keep it going in case there will be some buzz around it, so any request are welcome, just drop me a comment</p>
<p>Enjoy the conversions!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nicolabortignon.com/?feed=rss2&amp;p=35</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FOTB Here i&#8217;m coming!</title>
		<link>http://www.nicolabortignon.com/?p=15</link>
		<comments>http://www.nicolabortignon.com/?p=15#comments</comments>
		<pubDate>Fri, 23 Jul 2010 20:18:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://localhost:8888/wordpress4/?p=15</guid>
		<description><![CDATA[Ok, for those who don&#8217;t know this year, tnx to my boss i&#8217;m going to attend Flash On the Beach, that is, for those who don&#8217;t know the most inspired conference world wide for flash lovers (less formal and more exciting sessions). There is also a little small big thing to add&#8230; i was picked [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: right; margin: 0 0 0 5px;"  title="FLASH ON THE BEACH LOGO" src="http://www.nicolabortignon.com/external_file/fotb_logo_400x150.png" alt="" width="200" height="330" /></p>
<p>Ok, for those who don&#8217;t know this year, tnx to my <a href="http://www.mart3.org">boss</a> i&#8217;m going to attend Flash On the Beach, that is, for those who don&#8217;t know the most inspired conference world wide for flash lovers (less formal and more exciting sessions).</p>
<p>There is also a little small big thing to add&#8230; i was picked as elevator pitchers &#8230; a 3 minutes shots preso in wich i will show something (hope cool) in front of a stage of 1000 flash developer &#8230;. sounds scarring? yes it is!<br />
( i will come back later with some post on the work in progress  of the presentation )</p>
<p>But now let me show off my TODO LIST for FOTB!</p>
<p><strong>People I MUST meet!</strong><br />
Ok you know, community isn&#8217;t so big, but conference are great moment to meet people live, that is far away from exchanging mails or skype messages. Like every year, fotb is full of AS3 heros, and flash ecosystem great guys. This is my personal list (still upgrading &#8230; damn i think it&#8217;s quite impossible to have the same concentration of flash hero in the same place) :</p>
<p><span id="more-15"></span><br />
<a href="http://www.bytearray.org/">Thibault Imbert<br />
</a><br />
he&#8217;s simply alivepdf creator, bytearray proud pioneer, and recently was moved into flash player team&#8230;.. nothing to add. Must give him, the printed version of the poster i did.  I also expected some proof of his training to be a real geeky flash developer ( he should talk with a light saber instead of an usual laser pointer), i hope Mike Chambers keep controlling him on this.</p>
<div><img class="aligncenter" title="Poster Thibault Imbert" src="http://www.nicolabortignon.com/external_file/poster_thibault.png" alt="" width="400" height="507" /></div>
<p><a href="http://www.bit-101.com/">Keith Peters</a></p>
<p>Well just let me say <strong>minimalcomps.com</strong>. A project i used tons of time, a rising solid kit for superfast prototyping &#8230; i going few times throu customizing that components, and i&#8217;m sure a talk with the creator will open my mind to cool fresh ideas.</p>
<p><a href="http://lab.andre-michelle.com"> Andre Michelle</a></p>
<p>Another god in flash world, we remember him for the make some noise project, but till that time he&#8217;s keep moving on with such great ideas .. and hey &#8230; looks like he have a great music taste too !</p>
<p><a href="http://blog.joa-ebert.com/"> Joa Ebert</a></p>
<p>Ok, i&#8217;m following him since his previous blog posts over CI and other Software Engineer topic that at the end it&#8217;s exactly what i&#8217;m focus one. I&#8217;m sure there will be lot to learn from him!!</p>
<p><strong>Topics!</strong><br />
Even if the official session topics aren&#8217;t published yet, i&#8217;m sure there will be great topics to discuss over. This year my hot topics are:</p>
<p>CS5 Integration<br />
from the early studies looks like the cs5 sdk let us do such great things with as3 and the entire suit programms, so will be cool to know how deep we can get into this new toy</p>
<p><strong>air 2.0 and 10.1<br />
</strong> Everytime there is new release of flash player and air you can bet there are new feature that at the first time you don&#8217;t notice &#8230; Live listening the project team talking over this topic will open up our mind and give us a unpayable advance!</p>
<p><strong>Automated Processes<br />
</strong><br />
This is an advance topic, and i have lot to learn in this field. It&#8217;s all about integrating enterprise tools to turn flash into a solid developer solution even for high level business projects.</p>
<p><strong>Beach Experience!</strong></p>
<p>No, i&#8217;m not planning some beach time, there will not be time for that. Beach experience is just about feelings.. sharing &#8230; learn .. growing&#8230; i know that it sounds strange if you never come to FOTB, but i&#8217;m sure that all attenders, at least one time, they perfectly know what i mean</p>
<p>see you at FOTB : Brighton 26-29 September!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nicolabortignon.com/?feed=rss2&amp;p=15</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FlashIt! an Adobe Air version of the well know Apple Photo Booth</title>
		<link>http://www.nicolabortignon.com/?p=11</link>
		<comments>http://www.nicolabortignon.com/?p=11#comments</comments>
		<pubDate>Fri, 23 Jul 2010 15:21:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://localhost:8888/wordpress4/?p=11</guid>
		<description><![CDATA[Taking advantage of the Adobe YouGC Contest i decided to realize my personal submission focusing on the innovation introduced by adobe over the last years (no more than 2-3 after all). Adobe Air Api interaction and the software development process was off course the picked topic! I decided to recreate the well know (off course [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><img class="alignleft" style="float: left; margin: 0 5px 0 0;" src="http://www.nicolabortignon.com/external_file/flashit.png" alt="FlashIt! Screenshot" /> Taking advantage of the <a href="http://www.adobeyougc.com/#sez=Gallery;idProgetto=810">Adobe YouGC Contest</a> i decided to realize my personal submission focusing on the innovation introduced by adobe over the last years (no more than 2-3 after all).</p>
<p>Adobe Air Api interaction and the software development process was off course the picked topic!<br />
I decided to recreate the well know (off course for the mac users only <span class="smile"><img id="smile" src='http://www.nicolabortignon.com/wp-content/plugins/tango-smileys-extended/tango/wink.png' alt='Wink' title='Wink' class='tse-smiley' /></span> ) photo booth. If you are a window user or a linux user, you will find in this application probably a good replacement to the lack on your platform (however keep in consideration the idea to switch to mac).</p>
<p>Back to the submission, some interesting consideration on the workflow behind the realization:<br />
<span id="more-11"></span></p>
<p>1) Custom Interface.</p>
<p>I&#8217;m a flash developer, and i&#8217;m still convinced that the Catalyst &#8211; Flash Builder workflow isn&#8217;t optimized enought, so i prefeared to go straight to the old couple Photoshop + Flash cs4.</p>
<p>The entire design process took me around 3 hours. Including the logotype, the icon and the gui. I divided all in a well organized layers and groups,avoiding the use of masks and trying to  keep in mind that  i would import all in flash. Should sounds really exciting the small amount of hours needed for this phase, and the optimization on the import of the psd file (filters and text i still editable after import) is really useful, this is the props of having a giant as adobe behind, and looking to the cs5  preview looks like the path on integration inside creative suite will rise to an higher level. Perfect!</p>
<p>2) AIR features</p>
<p>For those who don&#8217;t know air bring the as3 knowledge from flash player to the desktop runtime, in few words, bring the web on your desktop. In this case we take advance also of the additional api that air offer, in particular the possibilities of interact with the operative system (open, reading and writing files), and the chance to drag file from application to desktop.</p>
<p>The first is quite common to all the air developer, if you are interesting on how to interact with the filesystem just take a look to the flash.filesystem package, and you will easily find how streams works in air.<br />
The second feature is a little bit tricky, since usually all the use case assume that the user drag a file from the desktop to the application, and rarely the viceversa, i spend a bit of time on finding a solution to let the user drag the thumbs inside the software to desktop, or every window that display a directory, transforming the image in a jpg valid file.<br />
Clipboard object helped me a lot on doing this! Clipboard object is much useful that I initially suppose to be; paring with the bytearray can esily take you to another level!</p>
<p>3) Image manipulation!<br />
this is probably the hot spot of the application, bitmap manipulation pixel by pixel. The main object in the as3 to handle pixels is BitmapData. This class has build in methods for creation and manipulation pixel data.<br />
This will let us:</p>
<p><strong> Manipulate each Pixel</strong> with getPixel(x,y) setPixel(x,y)  getPixels(rect:Rectangle) returns a ByteArray, setPixels(rect:Rectangle,bytes:ByteArray).</p>
<p><strong>Copying Pixels </strong>with clone(), copyPixels(), copyChannel(), draw()</p>
<p><strong>Other interesting things </strong>such as applyFilter(), colorTransform(), compare(), and the cool treshold().</p>
<p>This will help us creating such interesting filter, that reproduce lots of the most famous photoshop&#8217;s filters. I promise i will come back on this topic since there&#8217;s lot of interesting things to do with pixels.<br />
After manipulating pixmap data, you feel the needs to store in a bitmap with the draw(), and save it to an useful file for the user.<br />
Adobe developed officially a library that apply the jpg encoding process to bitmap, returning a byteArray. For sure i will come back on this to a specific topic.</p>
<p>4) Update manager system</p>
<p>This take me the longer time. I tried to implemented the ApplicationUpdater included in the 1.5 release of adobe Air, but i quickly felt uncomfortable, at the end i result with my own vision of an application update manager.<br />
In short we should:</p>
<ol>
<li style="list-style-type: lower-alpha"> Determine the update version string for your application (the new version you will be updating to)</li>
<li style="list-style-type: lower-alpha"> Download the correct version of that AIR application to local computer (preferably in the application resource directory)</li>
<li style="list-style-type: lower-alpha"> Create an instance of the Updater class</li>
<li style="list-style-type: lower-alpha"> Call the update method of the Updater class</li>
<li style="list-style-type: lower-alpha"> AIR will shut down your AIR application, install the new version, and then restart the application</li>
</ol>
<p>5) The missing list<br />
I decided to release the 1.0 version without some interesting featuring i planned at the begin such Video recording, mashup with social networks for direct upload, preview of thumbs into application, and so on.<br />
They are all on the to do list, and probably will comes in the future release, and any other requests are welcome</p>
<ul></ul>
<ul></ul>
<p>This article cover a little part of the entire process, but it should give you an overall idea of developing on the flash platform.</p>
<p>Following the link to the application. Adobe air 1.5 runtime is needed.</p>
<p style="text-align: center;">
<ul></ul>
<p><a href="http://www.italianraiders.com/flashit/FlashIt.air"><img src="http://www.italianraiders.com/img/download.png" alt="Download FlashIt!" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nicolabortignon.com/?feed=rss2&amp;p=11</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Bitwise Operations and Manipulations in AS3</title>
		<link>http://www.nicolabortignon.com/?p=1</link>
		<comments>http://www.nicolabortignon.com/?p=1#comments</comments>
		<pubDate>Fri, 23 Jul 2010 10:05:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://localhost:8888/wordpress4/?p=1</guid>
		<description><![CDATA[On the path of beeing the As3 world master scripter there is something important to know about number manipulation. Even if we are normally dealing with the as3 Number type such uint, int and Number as normal object (java type wrapper like), we can take advance on how the integer number are rappresented and handle [...]]]></description>
			<content:encoded><![CDATA[<p>On the path of beeing the As3 world master scripter there is something important to know about number manipulation.<br />
Even if we are normally dealing with the as3 Number type such  uint, int and Number as normal object (java type wrapper like), we can take advance on how the integer number are rappresented and handle by the flash player.</p>
<p>The base concept, as &#8220;Bitwise&#8221; may suggest, is to use the bit representation of the number.<br />
A number can be represented in an infinite number of ways. The representation we are used to is called decimal, or base 10.<br />
The binary, or base 2, number system is the one that computers use to represent numbers in memory. Since we&#8217;re dealing with base 2, there are only two digits available, namely 0 and 1. Each digit is multiplied by successive powers of two to obtain the number&#8217;s overall value.</p>
<p>Following some of the useful/interesting implementation of the art of handle bit.</p>
<p><span id="more-1"></span></p>
<h3>Moltiplication and Division by 2 (or multiple of 2)</h3>
<p><span style="font-weight: normal; font-size: 13px;">bitwise left and right shift</span></p>
<pre class="brush:as3">// this is the normal way to divide or moltiply y for a multiple of
// 2 (0,1,2,4,8...)

y *= 2^x;
y /= 2^x;

// this is the bitwise way to divide or moltiply,
// note that the X is the number of positions to shift the number

y &lt;&lt;= x // Moltiplication by 2^x
y &gt;&gt;= x // Division by 2^x</pre>
<p>Even if is possible only to moltiply/divide number by 0,1,2,4,8,16 and so on, consider that the bitwise function is faster up to 3.5 times of the usual one.</p>
<h3>Cast using bitshift</h3>
<p>Since the bitwise operation results in an integer value (int or uint) we can use the bitshifter also for casting Number to int (uint)<br />
This is 10% fastwer of the normal casting. This also can be used to emulate the math.floor on a double <span class="smile"><img id="smile" src='http://www.nicolabortignon.com/wp-content/plugins/tango-smileys-extended/tango/wink.png' alt='Wink' title='Wink' class='tse-smiley' /></span></p>
<pre class="brush:as3">
// Normal casting
x = int(1.232)

// casting with bitshifting
x = 1.232 &gt;&gt; 0;
</pre>
<h3>Swapping int with the Xor Operator ( ^ )</h3>
<p><span style="font-weight: normal; font-size: 13px;"> </span></p>
<p>The Exclusive disjunction, also called exclusive or (symbolized XOR or EOR), is a type of logical disjunction on two operands that results in a value of true if exactly one of the operands has a value of true. A simple way to state this is &#8220;one or the other but not both, but i&#8217;m sure you still know this. What probably you don&#8217;t is this advance and smart use of the XOR.</p>
<p>Assume that x and y are two int (uint) already sets.</p>
<pre class="brush:as3">
x = x ^ y;          //  x is equal to x^y       y is equal to y
y = x ^ y;          //  x is equal to x^y       y is equal to (x ^ y )^ y == x
x = x ^ y;          // x is equal to (x ^ x) ^ y  == y     y is equal to x
</pre>
<p>like explained in the comment you actually swap two variables without using an auxiliar one and this is also 1.4x times faster!</p>
<h3>Other interesting operations</h3>
<p>The modulo operator (%) can be easily replaced by an additive mask (with the AND &#8220;&amp;&#8221; operator).<br />
In other words, the number we need to use as our mask in order to perform a modulus operation on 2n is simply 2n &#8211; 1. To illustrate this, the following pairs of statements are all equivalent to one another:</p>
<pre class="brush:as3">
x = y % 8;
x = y &amp; 7;

x = y % 32;
x = y &amp; 31;

x = y % 256;
x = y &amp; 255;
</pre>
<p>The only difference is that using the mask is 6x faster than the normal modulo.<br />
For the same reason, using this way do determinate if a number is Even or Pair is much faster!</p>
<pre class="brush:as3">
isEven = (i &amp; 1) == 0;  // if i is even return true, elsewhere false.
</pre>
<p>the following one is probably the best one on encreasing performance side, it is 25x faster than the original Math.abs()</p>
<pre class="brush:as3">
//version 1
i = x &lt;&lt; 0 ? -x : x;
//version 2
i = (x ^ (x &gt;&gt; 31)) - (x &gt;&gt; 31);
</pre>
<p>Comparing two integers for equal sign</p>
<pre class="brush:as3">
eqSign = a ^ b &gt;= 0;
</pre>
<p>Sign flipping using NOT or XOR</p>
<pre class="brush:as3">
i = ~i + 1;
//or
i = (i ^ -1) + 1
</pre>
<h3>Bitmasks Theory</h3>
<p><span style="font-weight: normal; font-size: 13px;"> </span></p>
<p>So what masks are? they are exactly what you think they are, a way for masking something and show the rest. There are mainly 3 functions on using bitmask:</p>
<p><strong>Masking bits to 1</strong><br />
To turn certain bits on, the bitwise OR operation can be used.Knowing that Y OR 1 = 1 and Y OR 0 = Y. Therefore, to make sure a bit is on, OR can be used with a 1. To leave a bit unchanged, OR is used with a 0.</p>
<p><strong>Masking bits to 0</strong><br />
To change a bit from on to off using the OR operation bitwise AND is used. When a value is ANDed with a 1, the result is simply the original value, as in: Y AND 1 = Y. However, ANDing a value with 0 is guaranteed to return a 0, so it is possible to turn a bit off by ANDing it with 0: Y AND 0 = 0. To leave the other bits alone, ANDing them with a 1 can be done.</p>
<p><strong>Querying the status of a bit</strong><br />
It is possible to use bitmasks to easily check the state of individual bits regardless of the other bits. To do this, turning off all the other bits using the bitwise AND is done as discussed above and the value is compared with 0. If it is equal to 0, then the bit was off, but if the value is any other value, then the bit was on. What makes this convenient is that it is not necessary to figure out what the value actually is, just that it is not 0.</p>
<p>So for exemple if you want to know the value for the 5th bit of a 8-bit number just AND it with a 00010000 mask.</p>
<h3>Bitmasks Implementations in as3</h3>
<p>The main havy use of bitwise operation in as3 is refeared on handling color data.<br />
As you probably know there are mainly two type of colour on flash the 24 bit (with 3 channel, and 8bit (255 value) for each color channel) and the 32 bit (that add the Alpha channel with its 8 bit value). Working with colors can be really painfull if you don&#8217;t keep in mind that they are only bits! So forget substring doublets, forget the 10-base arithmetic and start using what you learn on the lines above.</p>
<pre class="brush:as3">
// EXTRACTING COMPONENTS
//24bit
var color:uint = 0x336699;
var r:uint = color &gt;&gt; 16;
var g:uint = color &gt;&gt; 8 &amp; 0xFF;
var b:uint = color &amp; 0xFF;

//32bit
var color:uint = 0xff336699;
var a:uint = color &gt;&gt; 24;
var r:uint = color &gt;&gt; 16 &amp; 0xFF;
var g:uint = color &gt;&gt;  8 &amp; 0xFF;
var b:uint = color &amp; 0xFF;
</pre>
<pre class="brush:as3">
// COMBINING  COMPONENTS
//24bit
var r:uint = 0x33;
var g:uint = 0x66;
var b:uint = 0x99;
var color:uint = r &lt;&lt; 16 | g &lt;&lt; 8 | b;

//32bit
var a:uint = 0xff;
var r:uint = 0x33;
var g:uint = 0x66;
var b:uint = 0x99;
var color:uint = a &lt;&lt; 24 | r &lt;&lt; 16 | g &lt;&lt; 8 | b;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nicolabortignon.com/?feed=rss2&amp;p=1</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
