<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: base2 code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 11:50:36 GMT</pubDate>
    <description>DZone Snippets: base2 code</description>
    <item>
      <title>Base 2 Conversion</title>
      <link>http://snippets.dzone.com/posts/show/688</link>
      <description>Converting from base 2 to int is easy&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; int('1010', 2)&lt;br /&gt;10&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The opposite is a bit involved.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; number = 1000&lt;br /&gt;&gt;&gt;&gt; hex2bin = {"0":"0000", "1":"0001", "2":"0010", "3":"0011",&lt;br /&gt;            "4":"0100", "5":"0101", "6":"0110", "7":"0111",&lt;br /&gt;            "8":"1000", "9":"1001", "A":"1010", "B":"1011",&lt;br /&gt;            "C":"1100", "D":"1101", "E":"1110", "F":"1111"}&lt;br /&gt;&gt;&gt;&gt; "".join([hex2bin[h] for h in '%X'%number]).lstrip('0')&lt;br /&gt;'1111101000'&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;See the def of toBase2(number) &lt;a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440528&gt;here&lt;/a&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 09 Sep 2005 14:51:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/688</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
