On Jul 11, 1:38 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Wed, 11 Jul 2007 10:46:23 -0700, [EMAIL PROTECTED] wrote:
> > You can with gmpy:
>
> >>>> import gmpy
> >>>> x = 0x0164
> >>>> s = gmpy.digits(x,2)      # convert to base 2
> >>>> y = '0'*(16-len(s)) + s   # pad to 16 bits
> >>>> y
> > '0000000101100100'
>
> For the padding I'd use the `zfill()` method.
>
> In [15]: a = 0x0164
>
> In [16]: gmpy.digits(a, 2).zfill(16)
> Out[16]: '0000000101100100'
>
> Ciao,
>         Marc 'BlackJack' Rintsch

Damn, I didn't know you could do that.
If only there was a built-in base 2 conversion.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to