binascii.unhexlify ... not clear about usage, and output
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Wed Jul 11 14:38:38 EDT 2007
On Wed, 11 Jul 2007 10:46:23 -0700, mensanator at aol.com 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
More information about the Python-list
mailing list