This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author abarnert
Recipients Ramchandra Apte, abarnert, christian.heimes, cowlicks, georg.brandl, gvanrossum, josh.r, martin.panter, pitrou, rhettinger, serhiy.storchaka, socketpair, terry.reedy, vstinner
Date 2016-01-10.15:20:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CD99D9D4-F255-4F37-B859-05F2FF9BDE7B@yahoo.com>
In-reply-to <1452437327.25.0.380801929125.issue19251@psf.upfronthosting.co.za>
Content
On Jan 10, 2016, at 06:48, cowlicks <report@bugs.python.org> wrote:
> 
> 
> Personally this came up while I was playing with toy crypto problems. I expected to already be part of the language, but it wasn't. I think this is a natural expectation.

Maybe if you're coming to Python from APL or R or something, but C, C#, Scala, Ruby, Haskell--almost any other language you pick, there's no bitwise operations on (byte) strings. (And if you _are_ coming to Python from something like R, you definitely should be using NumPy.)
> 
> And I do not understand how bitwise operations work on arbitrary precision integers.

It's obvious once you think of them as infinite-sized fixed-size ints: 0x27 is the same number as 0x0027, so 0x27 & 0x0134 is 0x0024. (Of course not and negation aren't quite as obvious, but once you think about it, there's only one sensible thing 2's complement could do, and only two sensible things 1's complement could do, and Python is sensible, so it's not surprising once you try it out.)

> Some folks have suggested using NumPy, but that is a very heavy dependency, and not useful outside of cpython.

It's useful outside of CPython. While NumPyPy isn't 100% yet, it's usable enough for many projects.

More to the point, if you're looking for arrays that have really fast and highly readable elementwise operations, that's exactly what NumPy is all about. Sure, you can get bits and pieces of similar functionality without it, but if you're thinking about your code in NumPy's terms (elementwise operations), you really do want to think about NumPy.

Meanwhile, have you looked around PyPI at the various bitarray, bitstring, etc. libraries? Are they too slow, too heavyweight, or too inconveniently-API'd? I know whenever I want to play with things like Huffman coding or the underlying bit representation of IEEE floats or anything else bitwise besides basic C integer stuff, I reach for one of those libraries, rather than trying to hack things up around bytes strings. (Except for that example I posted above--clearly for some reason I _did_ hack things up around bytes strings that time--but it only took me that simple class to make things convenient and efficient.)
History
Date User Action Args
2016-01-10 15:20:41abarnertsetrecipients: + abarnert, gvanrossum, georg.brandl, rhettinger, terry.reedy, pitrou, vstinner, christian.heimes, socketpair, Ramchandra Apte, martin.panter, serhiy.storchaka, josh.r, cowlicks
2016-01-10 15:20:41abarnertlinkissue19251 messages
2016-01-10 15:20:40abarnertcreate