473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

binascii.a2b_binary

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

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

What is the python way to do this?

Other fun with strings:
'3333'.decode('hex') '33' '3333'.encode('hex')

'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
Apr 3 '06 #1
2 1842
Ed Swarthout wrote:
Why is there no binascii.a2b_binary(bitstr) which returns the binary data
represented by the bit string? Like:
binascii.a2b_binary('0011001100110101')

'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
sc***********@acm.org
Apr 3 '06 #2
Ed Swarthout wrote:
Why is there no binascii.a2b_binary(bitstr) which returns the binary data
represented by the bit string? Like:
binascii.a2b_binary('0011001100110101')

'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))

Apr 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nobody | last post by:
1) Does anyone know if the CRC32 algorithm in binascii has a name? There seem to be a TON of different CRC32 methods; different polynomials, different byte orders, different seeds, some flip the...
12
by: Mercuro | last post by:
Hello i'm looking for a simple way to checksum my data. The data is 70 bytes long per record, so a 32 byte hex md5sum would increase the size of my mysql db a lot. I'm looking for something...
9
by: py | last post by:
Hi, I am encoding a string such as... data = someFile.readlines() encoded = for line in data: encoded.append(binascii.b2a_uu(stringToEncode)) return encoded
12
by: Larry Bates | last post by:
I'm trying to get the results of binascii.crc32 to match the results of another utility that produces 32 bit unsigned CRCs. binascii.crc32 returns results in the range of -2**31-1 and 2**21-1....
15
by: Claudio Grondi | last post by:
Let's consider a test source code given at the very end of this posting. The question is if Python allows somehow access to the bytes of the representation of a long integer or integer in...
1
by: Jeremy | last post by:
I'm working on a project to create a keyfinder program that finds the Windows CD Key in the registry and decodes it. I prototyped it in Python and it worked great but for several reasons I've...
10
by: Chason Hayes | last post by:
I am trying to convert raw binary data to data with escaped octets in order to store it in a bytea field on postgresql server. I could do this easily in c/c++ but I need to do it in python. I am...
0
by: yaipa | last post by:
I snipped this bit of code out of Andrew Kuchling 'pyCrypto' test fixture. Having a need to XOR Binascii Hex strings in my current project, I found it very helpful to cut down on a bit of code...
6
by: Vishal | last post by:
Hi, 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: .... x = line.rstrip('\n') .... y =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.