From: Mark <lists+zsh@internecto.net>
To: zsh-users@zsh.org
Subject: Re: logical NOT
Date: Sat, 12 May 2012 13:43:13 +0200 [thread overview]
Message-ID: <20120512134313.6b210e8e@internecto.net> (raw)
In-Reply-To: <CAHYJk3SgFybFyof4CdmTXxUOcuQZBMHOPFOwPq8TnG7CGrSdyw@mail.gmail.com>
Hello,
On Thu, 10 May 2012 20:02:46 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> On 10/05/2012, Bart Schaefer <schaefer@brasslantern.com> 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
prev parent reply other threads:[~2012-05-12 11:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-10 11:59 Mark van Dijk
2012-05-10 12:30 ` René Neumann
2012-05-10 12:47 ` Jérémie Roquet
2012-05-10 15:12 ` Bart Schaefer
2012-05-10 18:02 ` Mikael Magnusson
2012-05-12 11:41 ` Internecto List Subscriber
2012-05-12 11:43 ` Mark [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120512134313.6b210e8e@internecto.net \
--to=lists+zsh@internecto.net \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).