Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: logical NOT
Hello,
On Thu, 10 May 2012 20:02:46 +0200
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On 10/05/2012, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > On May 10, 1:59pm, Mark van Dijk wrote:
> > }
> > } Then I wondered about how to let zsh "reverse" a binary number
> > and came } up with the logical NOT: simply flip each bit.
> >
> > As others have noted, that gives you the number what might be
> > described as "upside down", rather than backward.
> >
> > mac2bin() {
> > setopt localoptions extendedglob
> > print ${(l:8::0:)${${(s.:.)1}//(#b)(*)/$(([#2]$match))}#2\#}
> > }
> >
> > reverse() {
> > setopt localoptions noksharrays
> > local i a
> > a=( ${(s::)*} )
> > for i in {$#a..1}; print -n -- $a[$i]
> > print
> > }
> >
> > torch% mac2bin AC:DE:48:00:00:80
> > 00000000 00000000 00110000 00000000 00000000 01010000
> > torch% reverse $(mac2bin AC:DE:48:00:00:80)
> > 00001010 00000000 00000000 00001100 00000000 00000000
>
> Reverse can also be implemented more confusingly with Oa,
> reverse() {
> setopt localoptions noksharrays
> print -r -- "${(j::)${(@Oa)${(s::)*}}}"
> }
Thanks everyone for the useful examples and comments! :)
Mark
Messages sorted by:
Reverse Date,
Date,
Thread,
Author