Well, I decided to implement my own way of doing this. I've attached the source. You're all welcome :)<br><br><div><span class="gmail_quote">On 8/12/07, <b class="gmail_sendername">Michael Bentley</b> <<a href="mailto:michael@jedimindworks.com">
michael@jedimindworks.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="">Hi Robert,<div><span class="q">
<br><div><div>On Aug 11, 2007, at 3:59 PM, Robert Dailey wrote:</div><blockquote type="cite">Hi, I was wondering if there is a built in module that supports conversion in any direction between Binary, Hex, and Decimal strings? Thanks.
</blockquote></div><br></span><div><span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
Shouldn't be too hard to build one. Here's a little incantation to convert from base 10 to another base:</span></div><div><br></div><div>import string</div><div><br></div><div>def to_base(number, base):</div><div>
<span style="white-space: pre;"> </span>'converts base 10 integer to another base'</div><div><br></div><div><span style="white-space: pre;"> </span>number = int(number)</div><div><span style="white-space: pre;"> </span>
base = int(base)<span style="white-space: pre;"> </span></div><div><span style="white-space: pre;"> </span>if base < 2 or base > 36:</div><div><span style="white-space: pre;"> </span>raise ValueError, "Base must be between 2 and 36"
<span style="white-space: pre;"> </span></div><div><span style="white-space: pre;"> </span>if not number:</div><div><span style="white-space: pre;"> </span>return 0</div><div><span style="white-space: pre;"> </span></div>
<div><span style="white-space: pre;"> </span>symbols = string.digits + string.lowercase[:26]<span style="white-space: pre;"> </span></div><div><span style="white-space: pre;"> </span>answer = []</div><div><span style="white-space: pre;">
</span>while number:</div><div><span style="white-space: pre;"> </span>number, remainder = divmod(number, base)</div><div><span style="white-space: pre;"> </span>answer.append(symbols[remainder])<span style="white-space: pre;">
</span></div><div><span style="white-space: pre;"> </span>return ''.join(reversed(answer))</div><div><span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<div><br></div><div>How 'bout you hack a from_base function and email it back to me? (hint: type 'help(int)' in the python interpreter).</div><div><br></div><div>Peace,</div><div>Michael</div><div><br></div><div>
---</div><div>Let the wookie win.</div><div><br></div><br></span></span> </div><br></div></div></blockquote></div><br>