From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10250 invoked by alias); 10 May 2012 12:38:10 -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: 17072 Received: (qmail 4293 invoked from network); 10 May 2012 12:38:09 -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 autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at necoro.eu does not designate permitted sender hosts) Message-ID: <4FABB4D7.7090308@necoro.eu> Date: Thu, 10 May 2012 14:30:15 +0200 From: =?ISO-8859-1?Q?Ren=E9_Neumann?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120502 Thunderbird/12.0.1 MIME-Version: 1.0 To: Mark van Dijk CC: zsh-users@zsh.org Subject: Re: logical NOT References: <20120510135934.00f00537@internecto.net> In-Reply-To: <20120510135934.00f00537@internecto.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit XOR with all ones to 'flip': echo $(( [#2] 0xAC ^ 0xFF )) 2#1010011 But this is not the 'reversal' in the sense of changing the bit-order (lsbf to msbf or vice versa). For the simple reversal of the bits, well ... use rev :) echo "2#"`echo $(( [##2] 0xAC )) | rev` 2#00110101 - René Am 10.05.2012 13:59, schrieb Mark van Dijk: > Before I explain what I need let me explain why I need it. > > Just now I was reading about MAC addresses, their binary > representation, and how MAC addresses are transmitted across a network. > This document mentions the address AC:DE:48:00:00:00. Converting that > to binary is easy: > > for i (${(s.:.):-AC:DE:48:00:00:80}) echo $(( [#2] hex=0x$i )) > > Here we can see 0xAC == 2#10101100. > > From what I understand this is transmitted over a network from right to > left, so the receiver will receive 00110101 in that order. In this > sequence the first transmitted bit represents the individual/group > address bit and the second one represents the universally/locally > administered address bit, the reason for me reading this. > > Then I wondered about how to let zsh "reverse" a binary number and came > up with the logical NOT: simply flip each bit. I've tried a lot of ways > but they all fail. What confuses me most is this: > > % echo $(( [#2] ~0xAC )) > -2#10101101 > > I'd appreciate thoughts on this, and to hear if it makes any sense at > all :) > > Thanks, > Mark. >