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

Re: logical NOT



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



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