<?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>Jozef Chúťka&#039;s blog &#187; BigInteger</title>
	<atom:link href="http://blog.yoz.sk/tag/biginteger/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.yoz.sk</link>
	<description>My life, my work</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:40:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Facebook profile album aid</title>
		<link>http://blog.yoz.sk/2009/10/facebook-profile-album-aid/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=facebook-profile-album-aid</link>
		<comments>http://blog.yoz.sk/2009/10/facebook-profile-album-aid/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 07:59:59 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[as3crypto]]></category>
		<category><![CDATA[BigDecimal]]></category>
		<category><![CDATA[BigInteger]]></category>
		<category><![CDATA[bit shifting]]></category>
		<category><![CDATA[facebook api]]></category>
		<category><![CDATA[FacebookUtils]]></category>
		<category><![CDATA[GetPhoto]]></category>
		<category><![CDATA[MathContext]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=493</guid>
		<description><![CDATA[In search of best practice to get your facebook default profile (archive) album I came to the official facebook api wiki page. It states there that it is possible to calculate aid (album id) from your uid (user id) by simple formula: Well, it may seem simple, but notice 32 bit left shifting in first [...]]]></description>
			<content:encoded><![CDATA[<p>In search of best practice to get your facebook default profile (archive) album I came to the <a href="http://wiki.developers.facebook.com/index.php/Profile_archive_album">official facebook api wiki page</a>. It states there that it is possible to calculate aid (album id) from your uid (user id) by simple formula:</p>
<pre class="brush: as3; title: ; notranslate">(uid &lt;&lt; 32) + (-3 &amp; 0xFFFFFFFF)</pre>
<p>Well, it may seem simple, but notice 32 bit left shifting in first part! By this operation on uid, you go far beyond integer max value and flash will not give you correct results. So how to do that?</p>
<p><span id="more-493"></span></p>
<p>First, I came to a <a href="http://code.google.com/p/as3crypto/source/browse/trunk/as3crypto/src/com/hurlant/math/BigInteger.as">BigInteger class</a> (part of <a href="http://code.google.com/p/as3crypto/">as3crypto</a>). This class lets you operate over big integers, but when you are finished there is no way you can convert your result into a decimal string that you need for facebook call.</p>
<p>Then I decided to use <a href="http://code.google.com/p/bigdecimal/">BigDecimal class</a>. This one let you input and output decimal strings and works perfectly for facebook purpose. To simplify it, I created static method profileAid() in <a href="http://classes.yoz.sk/sk/yoz/FacebookUtils.as">FacebookUtil class</a>:</p>
<pre class="brush: as3; title: ; notranslate">public static function profileAid(uid:String):String
{
	var v1:BigDecimal = new BigDecimal(uid);
	var v2:BigDecimal = new BigDecimal(2);
	var v3:BigDecimal = new BigDecimal(32);
	var v4:BigDecimal = new BigDecimal(4294967293);
	var v5:BigDecimal = new BigDecimal(3);
	var v6:BigDecimal = new BigDecimal(uint.MAX_VALUE.toString());

	var r:String = v1.compareTo(v6) == 1
		? v1.subtract(v5).toString()
		: v1.multiply(v2.pow(v3)).add(v4).toString();
	var l:Array = r.replace(&quot;,&quot;, &quot;.&quot;).split(&quot;.&quot;);
	return l[0];
}
</pre>
<h3>Solution</h3>
<p>You can use FacebookUtils.profileAid() directly in your facebook GetPhoto() calls:</p>
<pre class="brush: as3; title: ; notranslate">var aid:String = FacebookUtils.profileAid(facebook.uid)
facebook.post(new GetPhotos('', aid));</pre>
<p>I was not able to gather more information about BigDecimal class than this&#8230;</p>
<blockquote><p>This is a conversion of the IBM ICU implementation of the BigDecimal for ActionScript 3, (Flash or Flex) Compiled with SDK 3.2.0. Two files are needed, BigDecimal.as and MathContext.as You can also take BigDecimalTest.as if you need some testing. Files are in the Source->Browse->Trunk. Feel free to report bugs or errors if there are any. Thanks.</p></blockquote>
<p>&#8230;but I want to thank rouche (author&#8217;s nickname) for sharing BigDecimal class and ask him kindly to let me put this class into com.rouche.math package.</p>
<p>To sum it up, for your applications you gonna need:</p>
<ul>
<li><a href="http://classes.yoz.sk/com/rouche/math/BigDecimal.as">com.rouche.math.BigDecimal</a></li>
<li><a href="http://classes.yoz.sk/com/rouche/math/MathContext.as">com.rouche.math.MathContext</a></li>
<li><a href="http://classes.yoz.sk/sk/yoz/utils/FacebookUtils.as">sk.yoz.utils.FacebookUtils</a></li>
</ul>
<p>To test your generated aid results go to <a href="http://developers.facebook.com/tools.php">Facebook Test Console</a>, choose method photos.get and paste aid.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/10/facebook-profile-album-aid/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

