binascii.a2b_binary

E

Ed Swarthout

Why is there no binascii.a2b_binary(bitstr) which returns the binary data
represented by the bit string? Like:
'35'

perl has pack("B*", "0011001100110101");

What is the python way to do this?

Other fun with strings:
'33333333'

I easily found the doc for str.decode(), but it appears to only mention
encodings for languages. It took me a while to connect it to hex_codec.
Maybe a more direct link could be added.

Thanks,
-EdS
 
S

Scott David Daniels

Ed said:
Why is there no binascii.a2b_binary(bitstr) which returns the binary data
represented by the bit string? Like:

'35'
> perl has pack("B*", "0011001100110101");

What, you mean like:
int('0011001100110101', 2)
Which you could show as:
hex(int('0011001100110101', 2))

I guess because Python is not so wonderful as Perl. Apparently Python
stupidly forgot to follow Perl's great naming conventions.

--Scott David Daniels
(e-mail address removed)
 
S

Serge Orlov

Ed said:
Why is there no binascii.a2b_binary(bitstr) which returns the binary data
represented by the bit string? Like:

'35'

perl has pack("B*", "0011001100110101");

What is the python way to do this?

to post a question on comp.lang.python and have the code written by
somebody else :)

def a2b_binary(s):
return ''.join(chr(int(s[pos:pos+8],2)) for pos in
range(0,len(s),8))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top