<?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>goto 0</title>
	<atom:link href="http://goto0.cubelogic.org/feed" rel="self" type="application/rss+xml" />
	<link>http://goto0.cubelogic.org</link>
	<description>thoughts about programming</description>
	<lastBuildDate>Thu, 06 Oct 2011 08:40:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Steve Jobs</title>
		<link>http://goto0.cubelogic.org/a/235</link>
		<comments>http://goto0.cubelogic.org/a/235#comments</comments>
		<pubDate>Thu, 06 Oct 2011 07:36:00 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[idealism]]></category>
		<category><![CDATA[insanely great]]></category>
		<category><![CDATA[minimal design]]></category>
		<category><![CDATA[steve jobs]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=235</guid>
		<description><![CDATA[It&#8217;s weird. I&#8217;ve never had the privilege to work for Steve Jobs, let alone meet him or know him, yet it feels like someone close died. I was reflecting earlier on the fact that he is one of childhood heroes. From way back when I was a penny-less teenager, I was dreaming about owning a [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_248" class="wp-caption aligncenter" style="width: 310px"><a href="http://goto0.cubelogic.org/wp-content/uploads/2011/10/apple.com-2011-10-05-at-10.43.35-PM1.png"><img src="http://goto0.cubelogic.org/wp-content/uploads/2011/10/apple.com-2011-10-05-at-10.43.35-PM1-300x252.png" alt="apple.com 2011-10-05 at 10.43.35 PM" title="apple.com 2011-10-05 at 10.43.35 PM" width="300" height="252" class="size-medium wp-image-248" /></a><p class="wp-caption-text">apple.com 2011-10-05 at 10.43.35 PM</p></div>
<p>It&#8217;s weird. I&#8217;ve never had the privilege to work for Steve Jobs, let alone meet him or know him, yet it feels like someone close died.</p>
<p>I was reflecting earlier on the fact that he is one of childhood heroes. From way back when I was a penny-less teenager, I was dreaming about owning a Macintosh and program for it. Or make music with it. Or just play games. And soon later came the absurd <a href="http://en.wikipedia.org/wiki/Next_cube">NeXT cube</a>, with its black magnesium body. Oh, how I loved that thing. And its beautifully architected operating system. And this weird language no-one else was using, Objective-C.</p>
<p>The world lost a complex visionary. The one who declared floppy disks obsolete in circa 1989. The man who gave a name to those weird devices called &#8220;MP3 players&#8221; that nobody &#8211; nobody, I swear! &#8211; was using before the iPod. The guy who made me love iOS even if I hated its closed architecture. And the wise who insisted on the simplicity of single-button mice. Not forgetting the businessman unafraid to admit his LSD experiences.</p>
<p>Most importantly, he made me understand that engineering can meet with art and idealism. He is not the only one who has done it, but he is the only one that lived during my lifetime.</p>
<p>So, thank you <a href="http://apple.com/stevejobs">Steve Jobs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/235/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iOS 4.2 update and the Base SDK Missing error</title>
		<link>http://goto0.cubelogic.org/a/231</link>
		<comments>http://goto0.cubelogic.org/a/231#comments</comments>
		<pubDate>Mon, 06 Dec 2010 06:49:20 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[iOS SDK]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=231</guid>
		<description><![CDATA[If after updating to iOS 4.2 SDK you get a &#8220;Base SDK Missing&#8221; error: open Project settings and choose &#8220;Latest iOS&#8221; under Base SDK for All Configurations open your target and make sure the settings applies to it (in case you overrode it) (yes, somehow the &#8220;Base SDK Missing&#8221; error seems to stick) shutdown Xcode [...]]]></description>
			<content:encoded><![CDATA[<p>If after updating to iOS 4.2 SDK you get a &#8220;Base SDK Missing&#8221; error:</p>
<ol>
<li>open Project settings and choose &#8220;Latest iOS&#8221; under Base SDK for All Configurations</li>
<li>open your target and make sure the settings applies to it (in case you overrode it)</li>
<li>(yes, somehow the &#8220;Base SDK Missing&#8221; error seems to stick)</li>
<li>shutdown Xcode and reopen.</li>
</ol>
<p>The SDK now is set.</p>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/231/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building Erlang OTP R14B on OpenBSD 4.7</title>
		<link>http://goto0.cubelogic.org/a/215</link>
		<comments>http://goto0.cubelogic.org/a/215#comments</comments>
		<pubDate>Mon, 27 Sep 2010 23:30:10 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[OpenBSD]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=215</guid>
		<description><![CDATA[Summary: OpenBSD is not GNU/Linux! I just spent the last 20 minutes baffled by some weird errors as I was building Erlang on an OpenBSD box I am setting up. $ make make: "/home/acces/otp_src_R13B04/Makefile" line 88: Missing dependency operator make: "/home/acces/otp_src_R13B04/Makefile" line 89: Missing dependency operator ... 100 similar lines follow ... The problem is&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Summary: OpenBSD is not GNU/Linux!</p>
<p>I just spent the last 20 minutes baffled by some weird errors as I was building Erlang on an OpenBSD box I am setting up. </p>
<pre>$ make
make: "/home/acces/otp_src_R13B04/Makefile" line 88: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 89: Missing dependency operator
...
100 similar lines follow
...
</pre>
<p>The problem is&#8230; that when you type <code>make</code>, OpenBSD &#8212; and probably NetBSD and FreeBSD &#8212; all use <a href="http://www.openbsd.org/cgi-bin/man.cgi?query=make&#038;sektion=1">BSD make</a> by default, NOT <code>GNU make</code>! Silly me. I even had just installed <code>GNU make</code> a couple hours earlier!</p>
<p>So anyway:</p>
<pre>
$ pkg_add -i -v gmake
...
[download, unzip, configure Erlang OTP]
...
<del>$ make</del> # WILL FAIL!
$ gmake
</pre>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/215/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GitHub love</title>
		<link>http://goto0.cubelogic.org/a/209</link>
		<comments>http://goto0.cubelogic.org/a/209#comments</comments>
		<pubDate>Mon, 13 Sep 2010 07:30:04 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=209</guid>
		<description><![CDATA[I imported some of my open source code over to GitHub. I have to say I was surprised how easy and smooth the import went from my old svn repository. The whole history seems to have been imported nicely. Beside importing SimpleTimer (my first Cocoa app: beware, its code might not be the prettiest!), this [...]]]></description>
			<content:encoded><![CDATA[<p>I imported some of <a href="http://github.com/ettore">my open source code</a> over to GitHub. I have to say I was surprised how easy and smooth the import went from my old svn repository. The whole history seems to have been imported nicely. </p>
<p>Beside importing <a href="http://cubelogic.org/simpletimer">SimpleTimer</a> (my first Cocoa app: beware, its code might not be the prettiest!), this is the first release of <a href="http://cubelogic.org/clutils">CLutils</a>, my collection of C/C++/Objective-C functions built over the years. There&#8217;s not much structure in it, beside subdividing it by deployment platforms (Mac OS X, iOS and cross-platform code) and OS X APIs (Carbon, Cocoa).</p>
<p><a href="http://github.com/ettore/SimpleTimer/">http://github.com/ettore/SimpleTimer/</a><br />
<a href="http://github.com/ettore/CLutils/">http://github.com/ettore/CLutils/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/209/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FlashBuilder quirks</title>
		<link>http://goto0.cubelogic.org/a/205</link>
		<comments>http://goto0.cubelogic.org/a/205#comments</comments>
		<pubDate>Thu, 02 Sep 2010 06:12:49 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[FlashBuilder]]></category>
		<category><![CDATA[FlexBuilder]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=205</guid>
		<description><![CDATA[I ran into the following weird compile error recently: compile error: 1071: Syntax error: expected a definition keyword (such as function) after attribute override, not protected. in relation to the following code: override protected function createChildren():void {} The solution? override protected function createChildren():void {} Don&#8217;t even get me started.]]></description>
			<content:encoded><![CDATA[<p>I ran into the following weird compile error recently:</p>
<pre>
<code>compile error:
1071: Syntax error: expected a definition keyword (such as function) after attribute override, not protected.
</code>
</pre>
<p>in relation to the following code:</p>
<pre>
<code>
override
protected function createChildren():void {}
</code>
</pre>
<p>The solution? </p>
<pre>
<code>
override protected function createChildren():void {}
</code>
</pre>
<p>Don&#8217;t even get me started.</p>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/205/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating your Apple Push Notification Service certificates</title>
		<link>http://goto0.cubelogic.org/a/186</link>
		<comments>http://goto0.cubelogic.org/a/186#comments</comments>
		<pubDate>Tue, 31 Aug 2010 06:13:22 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[iOS SDK]]></category>
		<category><![CDATA[push notifications]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=186</guid>
		<description><![CDATA[Just a quick checklist to get up to speed when your APN certificates expire. Login into the Provisioning Portal, click &#8220;App IDs&#8221; on the left side column Click &#8220;Configure&#8221; on the App ID of your app Click Revoke for the expired Push SSL certificate Open Keychain Access on your Mac. Click the &#8220;Certificates&#8221; category, find [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick checklist to get up to speed when your APN certificates expire.</p>
<ol>
<li>Login into the <a href="https://developer.apple.com/iphone/manage/bundles/index.action">Provisioning Portal</a>, click &#8220;App IDs&#8221; on the left side column</li>
<li>Click &#8220;Configure&#8221; on the App ID of your app</li>
<li>Click Revoke for the expired Push SSL certificate</li>
<li>Open Keychain Access on your Mac. Click the &#8220;Certificates&#8221; category, find the expired cert and just delete it.</li>
<li>From the Provisioning Portal website, start creating a brand new Push SSL certificate. Just follow the instructions. </li>
<li>Don&#8217;t forget to download the signed cert and double-click it to install it (<code>aps_developer_identity.cer</code>) in your default keychain.</li>
<li>Find the newly created cert in Keychain Access and click the disclose triangle. Then:
<ul>
<li>- Right-click on the private key entry without selecting the parent, and select Export. A <code>.p12</code> file will be saved </li>
<li>- Right-click on the actual certificate <em>without</em> selecting the child key, and select Export. Another <code>.p12</code> file will be saved </li>
</ul>
</li>
<li>If your server requires <code>.pem</code> style certificates, run this:
<pre>
$ openssl pkcs12 -in apn_cert.p12 -out apn_cert.pem -nodes
$ openssl pkcs12 -in apn_key.p12 -out apn_key.pem -nodes
</pre>
</li>
<li>Deploy the <code>.pem</code> files in the right location accessible by your application server that will be sending the Push notifications.</li>
</ol>
<p>Now push notifications should be up and running once again.</p>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/186/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickly rebuild your iOS app when Provisioning Profile expires</title>
		<link>http://goto0.cubelogic.org/a/172</link>
		<comments>http://goto0.cubelogic.org/a/172#comments</comments>
		<pubDate>Sun, 29 Aug 2010 05:52:07 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[provisioning profiles]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=172</guid>
		<description><![CDATA[Login into the Provisioning Portal, click &#8220;Provisioning&#8221; on the left side column Renew your expired profile (or create new one) and download it Drag it over the Xcode dock icon (or add it into the Organizer) Remove old profiles from Xcode Organizer Open your Device target. Select the Build tab -> Code Signing Identity, and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://goto0.cubelogic.org/wp-content/uploads/2010/08/prov-proft.png"><img src="http://goto0.cubelogic.org/wp-content/uploads/2010/08/prov-proft.png" alt="" title="prov-proft" width="325" height="129" class="alignleft size-full wp-image-176" /></a></p>
<ol>
<li>Login into the <a href="https://developer.apple.com/iphone/manage/provisioningprofiles/index.action">Provisioning Portal</a>, click &#8220;Provisioning&#8221; on the left side column</li>
<li>Renew your expired profile (or create new one) and download it</li>
<li>Drag it over the Xcode dock icon (or add it into the Organizer)</li>
<li>Remove old profiles from Xcode Organizer</li>
<li>Open your Device target. Select the <em>Build</em> tab -> <em>Code Signing Identity</em>, and <strong>make sure the new profile is the one in use</strong>.<br />
Xcode has the habit of not automatically updating its targets to use the newly installed provisioning profile. (Even if you physically removed the old one.) </li>
</ol>
<p>At this point you should be able to rebuild the app.</p>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/172/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bitstrings and Binaries (Erlang bit syntax minihowto part 2)</title>
		<link>http://goto0.cubelogic.org/a/142</link>
		<comments>http://goto0.cubelogic.org/a/142#comments</comments>
		<pubDate>Mon, 26 Jul 2010 04:24:57 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[bitstrings]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=142</guid>
		<description><![CDATA[What&#8217;s the difference between the Binary and Bitstring types in Erlang? Well, a bitstring is a sequence of bits of any length; a binary is a sequence of bits where the number of bits is evenly divisible by 8. (So any binary is also a bitstring.) Some examples: 1> &#60;&#60;2#11110000:5>>. < &#60;16:6>> 2> &#60;&#60;2#11110000:6>>. < [...]]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s the difference between the Binary and Bitstring types in Erlang?  Well, a <strong>bitstring</strong> is a sequence of bits of any length; a <strong>binary</strong> is a sequence of bits where the number of bits is evenly divisible by 8. (So any binary is also a bitstring.)</p>
<p>Some examples:</p>
<pre>
<code>1> &lt;&lt;2#111<strong>10000</strong>:5>>.
< &lt;16:6>>
2> &lt;&lt;2#11<strong>110000</strong>:6>>.
< &lt;48:6>>
3> erlang:is_bitstring(&lt;&lt;2#11110000:6>>).
true
4> erlang:is_binary(&lt;&lt;2#11110000:6>>).
<strong>false</strong>
5> erlang:is_bitstring(&lt;&lt;2#11110000:8>>).
true
6> erlang:is_binary(&lt;&lt;2#11110000:8>>).
true
</code></pre>
<p>In the <a href="http://goto0.cubelogic.org/a/90">Erlang bit syntax</a> there are 2 clarifying (?) type synonyms: </p>
<pre>
<code>bytes == binary
bits  == bitstring</code>
</pre>
<p>which are basically telling you to think of binaries as sequence of bytes, and bitstrings as sequence of bits. Quite obvious right? Well, it wasn&#8217;t for me at first.</p>
<p>It&#8217;s also worth noting how binaries and bitstrings are converted into text strings. Given the binary <code>&lt;&lt;16#50>></code> storing the letter &#8216;P&#8217;, </p>
<pre>
<code>7> &lt;&lt;16#50>>
<strong>&lt;&lt;"P">></strong>
8>erlang:bitstring_to_list(&lt;&lt;16#50>>). #I could've used binary_to_list()
<strong>"P"</strong>          <em>%great!</em>
9>erlang:bitstring_to_list(&lt;&lt;16#50:5>>).
<strong>[&lt;&lt;16:5>>]</strong>  <em>%mmh...</em>
</code></pre>
<p>The result of command #9 is not exactly what I had imagined. Yes, it&#8217;s a list, but it&#8217;s certainly not a text string, and I was expecting a text string.  Why was I expecting a text string if the API is named <code>bitstring_to_list()</code> ? Because if I was in the middle of coding a text manipulation algorithm and called <code>bitstring_to_list()</code>, I would probably (wrongly) assume that it would do some magic and transform <em>any</em> bitstring in a usable <em>text string</em>. Why? Because we are used to treat text strings as lists.  Why? Because we don&#8217;t have APIs that mention &#8220;strings&#8221;: all the builtin APIs only mention lists. That&#8217;s the problem. We are using a list API as if it was a string API, when a generic list is not necessarily a string.</p>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/142/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Changing a UIButton title and dealing with button States</title>
		<link>http://goto0.cubelogic.org/a/116</link>
		<comments>http://goto0.cubelogic.org/a/116#comments</comments>
		<pubDate>Thu, 22 Jul 2010 05:10:14 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iOS SDK]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[UIButton]]></category>
		<category><![CDATA[UIKit]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=116</guid>
		<description><![CDATA[If you are changing the title of a UIButton programmatically, you will naturally use the method setTitle:forState:. Easy enough&#8230; well, sort of. What do you put in the state parameter? My first reaction was &#8220;I&#8217;m going to put all possible states since I just want the button title to change no matter what.&#8221; So I [...]]]></description>
			<content:encoded><![CDATA[<p>If you are changing the title of a UIButton programmatically, you will naturally use the method <strong><code>setTitle:forState:</code></strong>. Easy enough&#8230; well, sort of. What do you put in the state parameter?</p>
<p>My first reaction was &#8220;I&#8217;m going to put all possible states since I just want the button title to change no matter what.&#8221; So I blindly <em>bit-OR</em>&#8216;ed all the possible values defined in the docs. </p>
<pre><code>
[myButton setTitle:@"New Title"
          forState:UIControlStateNormal | UIControlStateHighlighted | UIControlStateDisabled | UIControlStateSelected];</code></pre>
<p>Sound reasonable right? Wrong. If you do that here, your button title is probably not going to change at all. The problem is that the &#8220;normal&#8221; state (per Apple docs that&#8217;s &#8220;enabled, not selected, not highlighted&#8221;) is defined as such:</p>
<pre>
<code>enum {
    <strong>UIControlStateNormal   = 0,</strong>
    UIControlStateHighlighted  = 1 &lt;&lt; 0,
    UIControlStateDisabled     = 1 &lt;&lt; 1,
    UIControlStateSelected     = 1 &lt;&lt; 2,
    ...
}
</code>
</pre>
<p>so if you bit-OR all of them you are actually going to set the title for ALL states EXCEPT the &#8220;normal&#8221; (most common) state!</p>
<p>Sigh&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/116/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erlang bit syntax mini How-To</title>
		<link>http://goto0.cubelogic.org/a/90</link>
		<comments>http://goto0.cubelogic.org/a/90#comments</comments>
		<pubDate>Wed, 26 May 2010 09:36:05 +0000</pubDate>
		<dc:creator>ettore</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[bitstrings]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://goto0.cubelogic.org/?p=90</guid>
		<description><![CDATA[I don&#8217;t know why but Erlang bit syntax always confused me. I always skipped it while reading the docs, until, well, now that I need it. I should say this is not meant to be an exhaustive how-to by any means. It&#8217;s just a collection of notes, but howto sounded better. :) There are better [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know why but Erlang bit syntax always confused me. I always skipped it while reading the docs, until, well, now that I need it. I should say this is not meant to be an exhaustive how-to by any means. It&#8217;s just a collection of notes, but howto sounded better. :) There are <a href="http://learnyousomeerlang.com/starting-out-for-real#bit-syntax">better guides out there</a>. [<a href="http://www.erlang.org/doc/reference_manual/expressions.html#bit_syntax">Reference docs too</a>.]</p>
<p>Anyway. Here&#8217;s some binary data in Erlang:</p>
<pre>&lt;&lt;16#1192c05a:32>></pre>
<p>What does all this mean? Let&#8217;s analyze it, left to right.</p>
<ol>
<li><strong><code>16#</code></strong>   This specifies we want to express the number in base 16.</li>
<li>We have an eight digits hex number.</li>
<li>No type specification is provided: default is unsigned integer.</li>
<li>No unit specification is provided: default for integer is 1, which means &#8216;bits&#8217;.</li>
<li><strong><code>:32</code></strong>   Size specification: this tells erlang to consider 32 units, which in our case means 32 bits, since we are dealing with bits.</li>
</ol>
<p>Let&#8217;s evaluate it:</p>
<pre>86> &lt;&lt;16#2092105a:32>>.
&lt;&lt;32,146,16,90>></pre>
<p>What if we forget to specify the size spec? In that case the default will apply and since we&#8217;re dealing with an integer type, the default is 8 (bits). For Erlang this means we are going to return the least significant byte:</p>
<pre>87> &lt;&lt;16#2092105a>>.
&lt;&lt;90>></pre>
<p>Now that we know that, we can get a subset of bits by setting the size accordingly:</p>
<pre>88> &lt;&lt;16#2092105a:16>>.
&lt;&lt;16,90>>     %two least significant bytes
</pre>
<p>We don&#8217;t need to specify a size multiple of 8:</p>
<pre>89> &lt;&lt;16#1192FFFF:15>>.
&lt;&lt;255,127:7>></pre>
<p>It&#8217;s pretty cool how easy it is to slice bytes apart at the bit level. I was sort of surprised that if we slice some internal bits it looks like the bits at the right are moved to the left.  E.g. here we take the 4 least significant bits of the first 0xFF:</p>
<pre>90> &lt;&lt;16#FF:4,0,16#FF,0>>.</pre>
<p>but instead of obtaining:</p>
<pre>&lt;&lt;16:4,0,255,0>>
F 00 FF 00</pre>
<p>we get:</p>
<pre>&lt;&lt;240,15,240,0:4>>
F0 0F F0 0          [240 == F0]</pre>
<p>Also, the value doesn&#8217;t need to be a literal, it can be an expression:</p>
<pre>91> N = 16#FF00FF01.
4278255361
92> &lt;&lt;N:32>>.
&lt;&lt;255,0,255,1>>
</pre>
<p>And therefore, given some binary data, we can also pattern-match it super easily:</p>
<pre>&lt;SourcePort:16, DestinationPort:16, CheckSum:16, Payload/binary>> = SomeBinary.</pre>
<p>There&#8217;s more to Erlang bit syntax than this, but I&#8217;ll stop here for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://goto0.cubelogic.org/a/90/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

