From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24457 invoked by alias); 10 May 2012 15:12:46 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17074 Received: (qmail 15245 invoked from network); 10 May 2012 15:12:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120510081212.ZM14892@torch.brasslantern.com> Date: Thu, 10 May 2012 08:12:12 -0700 In-reply-to: <20120510135934.00f00537@internecto.net> Comments: In reply to Mark van Dijk "logical NOT" (May 10, 1:59pm) References: <20120510135934.00f00537@internecto.net> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: logical NOT MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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