<?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; p16Top64</title>
	<atom:link href="http://blog.yoz.sk/tag/p16top64/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>Compressing hex string into base64 string</title>
		<link>http://blog.yoz.sk/2009/11/compressing-hex-string-into-base64-string/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=compressing-hex-string-into-base64-string</link>
		<comments>http://blog.yoz.sk/2009/11/compressing-hex-string-into-base64-string/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 12:16:00 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[compress]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[p16Top64]]></category>
		<category><![CDATA[p64Top16]]></category>
		<category><![CDATA[readUnsignedInt]]></category>
		<category><![CDATA[writeUnsignedInt]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=718</guid>
		<description><![CDATA[How would you convert / compress 64 character long hex string (0-9a-f) into shortest possible web-safe-char string? (base64 chars is fine) The reverse algorithm must be able to &#8220;uncompress&#8221; resulting string back into original hex. I have created p16Top64() compress algorithm and p64Top16() uncompress (reversed) algorithm based on ByteArray class and writeUnsignedInt(), readUnsignedInt() methods. Both [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.yoz.sk/wp-content/uploads/compressLooseWeight1.jpg"><img src="http://blog.yoz.sk/wp-content/uploads/compressLooseWeight1-200x120.jpg" alt="compressLooseWeight" title="compressLooseWeight" width="200" height="120" class="alignleft size-medium wp-image-733" /></a></p>
<p>How would you convert / compress 64 character long hex string (0-9a-f) into shortest possible web-safe-char string? (base64 chars is fine) The reverse algorithm must be able to &#8220;uncompress&#8221; resulting string back into original hex.</p>
<p>I have created p16Top64() compress algorithm and p64Top16() uncompress (reversed) algorithm based on ByteArray class and writeUnsignedInt(), readUnsignedInt() methods. Both p16Top64() and p64Top16() methods are now part of <a href="http://classes.yoz.sk/sk/yoz/data/Serialization.as">sk.yoz.data.Serialization</a> class. By using p16Top64() method I was able to compress original 64 chars into 44 chars. But, is it possible to compress it into less than 44 char long base64 (0-9a-Z/=) string?</p>
<p><span id="more-718"></span></p>
<p>To be more specific lets assume your original string is:</p>
<pre class="brush: plain; title: ; notranslate">295eb2c90b37696bb9256d05e404ad037078092214ce73cbe838302a04818507</pre>
<p>My compress and uncompress methods:</p>
<pre class="brush: as3; title: ; notranslate">import com.dynamicflash.util.Base64; // !use this Base64 class!

public static function p16Top64(p16:String):String
{
    var b:ByteArray = new ByteArray();
    var s:String = p16;
    while(s.length)
    {
        b.writeUnsignedInt(parseInt(&quot;0x&quot; + s.substr(0, 8), 16));
        s = s.substr(8);
    }
    b.position = 0;
    return Base64.encodeByteArray(b);
}

public static function p64Top16(p64:String):String
{
    var r:String = &quot;&quot;;
    var b:ByteArray = Base64.decodeToByteArray(p64);
    var x:String = &quot;&quot;;
    b.position = 0;
    while(b.position &lt; b.length)
    {
        x = b.readUnsignedInt().toString(16);
        r += String(&quot;00000000&quot;).substr(x.length) + x;
    }
    return r;
}</pre>
<p>Lets test it:</p>
<pre class="brush: as3; title: ; notranslate">Serialization.p16Top64(&quot;295eb2c90b37696bb9256d05e404ad037078092214ce73cbe838302a04818507&quot;)
// returns 64 chars.: KV6yyQs3aWu5JW0F5AStA3B4CSIUznPL6DgwKgSBhQc=</pre>
<p>This is more less first time I have used ByteArray this way, so maybe there is even a better usage. If you can think of one, just let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/11/compressing-hex-string-into-base64-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

