From: "René Neumann" <lists@necoro.eu>
To: Mark van Dijk <lists+zsh@internecto.net>
Cc: zsh-users@zsh.org
Subject: Re: logical NOT
Date: Thu, 10 May 2012 14:30:15 +0200 [thread overview]
Message-ID: <4FABB4D7.7090308@necoro.eu> (raw)
In-Reply-To: <20120510135934.00f00537@internecto.net>
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.
>
next prev parent reply other threads:[~2012-05-10 12:38 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 [this message]
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
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=4FABB4D7.7090308@necoro.eu \
--to=lists@necoro.eu \
--cc=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).