Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Carlos Newsgroups: comp.lang.postscript Subject: Re: Reversing the bits in a byte Date: Sat, 2 Dec 2017 12:46:13 +0100 Organization: A noiseless patient Spider Lines: 23 Message-ID: <20171202124613.29bdcab2@samara.DOMA> References: <3034e442-21ab-4c37-aef0-fb1b60a49856@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: reader02.eternal-september.org; posting-host="83aa1c7ced58b0631e3711c2cb4160c6"; logging-data="28030"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18DUV4lckaTez5tGbawnyg7irdAeiI/cnM=" X-Newsreader: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) Cancel-Lock: sha1:WaK0N+wjd/D/b+30tei/E/wSoXw= Xref: csiph.com comp.lang.postscript:3202 [luser droog , 2017-12-01 21:28] [...] > %reverse the bits in a byte [...] > Now applying this new idea, which I have also explained at: > > https://codereview.stackexchange.com/a/181823/5912 > > I get this, which appears much simpler: > > /reverse8 { > dup 4 bitshift exch -4 bitshift or > dup 16#33 and 2 bitshift exch 16#cc and -2 bitshift or > dup 16#55 and 1 bitshift exch 16#aa and -1 bitshift or > } def > > Exchange the two nibbles, then exchange chomps (?) in each nibble, > then exchange the bits in each chomp. Is there any better way? Another possibility is to use a lookup array. (I don't know which one is faster or better.) --