develooper Front page | | Postings from August 2002

Re: this must be golfable

Thread Previous | Thread Next
Phil Carmody
August 11, 2002 06:35
Re: this must be golfable
Message ID:
--- Eugene van der Pijll <> wrote:
> And on 11 sextil 2002 said Phil Carmody:
> > One way:
> > 
> > perl -pe '$_=y/o |./10/d?pack(B8,$_):""'

I'd just realised 
    perl -pe '$_=y/o |./10/d&&pack(B8,$_)'

>   perl -pe '$_=y/|.//d?pack(B8,$_):""'
>   perl -ne 'y/|.//d&&print pack B8,$_'

which implies that 
    perl -pe '$_=y/|.//d&&pack(B8,$_)'
should work too.

> In perl there are 256 binary digits.

Likewise, the "b" and "B" fields pack a string 
that many bits long.  Each byte of the
input field of pack() generates 1 bit of the 
result.  Each result bit is based on the
least-significant bit of the corresponding 
input byte, i.e., on "ord($byte)%2".  In par´┐Ż
ticular, bytes "0" and "1" generate bits 0 
and 1, as do bytes "\0" and "\1".


So - the reverse direction seems fair game now. It can't be much
longer than
the above, can it?


The good Christian should beware of mathematicians, and all those who make 
empty prophecies. The danger already exists that the mathematicians have 
made a covenant with the devil to darken the spirit and to confine man in 
the bonds of Hell. -- Common mistranslation of St. Augustine (354-430)

Do You Yahoo!?
HotJobs - Search Thousands of New Jobs

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About