bitwise AND, OR, XOR, NOT for strings?

D

David Garamond

(reposted via c.l.r from another email account; post to mailing list
doesn't seem to get through)

What do people think of adding String#&, String#|, String#^, and
String#~? I find it useful sometimes in Perl. In Ruby currently I have
to convert each byte to integer first, rather slow (actually slow as
mollasses... :)

There are BitSet and BitVector modules (and another one which I forgot
for doing bit operations) but ironically none of them currently
provide an easy way to xor two strings together.
 
R

Robert Klemme

David Garamond said:
(reposted via c.l.r from another email account; post to mailing list
doesn't seem to get through)

What do people think of adding String#&, String#|, String#^, and
String#~? I find it useful sometimes in Perl. In Ruby currently I have
to convert each byte to integer first, rather slow (actually slow as
mollasses... :)

There are BitSet and BitVector modules (and another one which I forgot
for doing bit operations) but ironically none of them currently
provide an easy way to xor two strings together.

I once hacked some BitSet together that could be initialized with a String
and converted back to a String. If you're interested I could mail it to
you. (If I find it back, that is. :))

robert
 
A

Ara.T.Howard

(reposted via c.l.r from another email account; post to mailing list
doesn't seem to get through)

What do people think of adding String#&, String#|, String#^, and
String#~? I find it useful sometimes in Perl. In Ruby currently I have
to convert each byte to integer first, rather slow (actually slow as
mollasses... :)

There are BitSet and BitVector modules (and another one which I forgot
for doing bit operations) but ironically none of them currently
provide an easy way to xor two strings together.

this is a great idea. it might also be useful to have

String.and! other
String.or! other
String.xor! other
String.not!

which did not create copies.

-a

--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
===============================================================================
 
D

David Garamond

Ara.T.Howard said:
this is a great idea. it might also be useful to have

String.and! other
String.or! other
String.xor! other
String.not!

which did not create copies.

Thanks for the responses. I'm gonna try submitting this as an RCR.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top