Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: logical NOT



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.
> 



Messages sorted by: Reverse Date, Date, Thread, Author