Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: logical NOT
- X-seq: zsh-users 17075
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: logical NOT
- Date: Thu, 10 May 2012 20:02:46 +0200
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=p/ZHblBSyyLADr9hAbq6dIws4KHjc8UHvc/lwxxPrrs=; b=a16P+j2nx4ux0TgCU0ZkdeRyfd80P9R2NAOMb3DROuykYc/kODwbLUyGfsjgaalXSQ lwOpv8VSKO9MxVr55TZ/q0L72uTyi7yWxF32p6RY59vGX3EXMnCZLp+0FEc2XtOcIKxe rEzoEkuTyWiCTRuGhJX4PORGyeP3HyAaWOqkCvCzaK43wBboRVenQqxTFXyCELO0m5m9 Mksvih5c2m/K37G7zi8Qsv34Z9ZxWgxmlKcVIMm52fHzZ41dGnpMyAeuI97LnBBB6Nhz 0iaEOXzryXOiT95Tx7ug8z3pMf57u1myX/oW4fP3pN3su3RqtzA7KLaFvN16axQSlA/3 1VdA==
- In-reply-to: <120510081212.ZM14892@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20120510135934.00f00537@internecto.net> <120510081212.ZM14892@torch.brasslantern.com>
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::)*}}}"
}
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author