zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: logical NOT
Date: Thu, 10 May 2012 08:12:12 -0700	[thread overview]
Message-ID: <120510081212.ZM14892@torch.brasslantern.com> (raw)
In-Reply-To: <20120510135934.00f00537@internecto.net>

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


  parent reply	other threads:[~2012-05-10 15:12 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 [this message]
2012-05-10 18:02   ` Mikael Magnusson
2012-05-12 11:41     ` Internecto List Subscriber
2012-05-12 11:43     ` Mark

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=120510081212.ZM14892@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --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).