En Wed, 11 Jul 2007 17:34:04 -0300, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> escribió:
> If only there was a built-in base 2 conversion.
No builtin, but you can find uncountable versions if you search this
group, or the Python cookbook, or the entire web...
--
Gabriel Genellina
--
http://mai
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
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
> '000101100100'
For the padding I'd use the `zfill()` method.
In [1
On Jul 11, 3:21 am, Vishal <[EMAIL PROTECTED]> wrote:
> On May 30, 1:31 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Vishal wrote:
> > > I have a file with a long list of hex characters, and I want to get a
> > > file with corresponding binary characters
>
> > > here's what I did:
>
> >
On May 30, 1:31 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> Vishal wrote:
> > I have a file with a long list of hex characters, and I want to get a
> > file with corresponding binary characters
>
> > here's what I did:
>
> import binascii
> f1 = 'c:\\temp\\allhex.txt'
> f2 = 'c:\\te
Vishal wrote:
> I have a file with a long list of hex characters, and I want to get a
> file with corresponding binary characters
>
> here's what I did:
>
import binascii
f1 = 'c:\\temp\\allhex.txt'
f2 = 'c:\\temp\\allbin.txt'
sf = open(f1, 'rU')
df = open(f2, 'w')