Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #3128
| From | Robert Wessel <robertwessel2@yahoo.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: bit twiddling hacks |
| Message-ID | <dabaj89qlb10f5o11341b1df2kds8iist1@4ax.com> (permalink) |
| References | <991e0977-0ea0-4e25-b71b-3c798f729614@googlegroups.com> |
| Organization | Forte Inc. http://www.forteinc.com/apn/ |
| Date | 2013-03-04 17:29 -0600 |
On Mon, 4 Mar 2013 15:09:54 -0800 (PST), bob <bob@coolfone.comze.com>
wrote:
>How do people typically come up with bit twiddling hacks like this?
>
> public static long reverse(long v) {
> // Hacker's Delight 7-1, with minor tweak from Veldmeijer
> // http://graphics.stanford.edu/~seander/bithacks.html
> v = ((v >>> 1) & 0x5555555555555555L) | ((v & 0x5555555555555555L) << 1);
> v = ((v >>> 2) & 0x3333333333333333L) | ((v & 0x3333333333333333L) << 2);
> v = ((v >>> 4) & 0x0F0F0F0F0F0F0F0FL) | ((v & 0x0F0F0F0F0F0F0F0FL) << 4);
> v = ((v >>> 8) & 0x00FF00FF00FF00FFL) | ((v & 0x00FF00FF00FF00FFL) << 8);
> v = ((v >>>16) & 0x0000FFFF0000FFFFL) | ((v & 0x0000FFFF0000FFFFL) <<16);
> return ((v >>>32) ) | ((v ) <<32);
> }
Clever minds, long nights, excessive caffeine consumption...
As to that particular method for reversing a set of bits, it dates
back to *at least* the sixties. And I would expect that it was known
almost since the dawn of modern computing.
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
bit twiddling hacks bob <bob@coolfone.comze.com> - 2013-03-04 15:09 -0800
Re: bit twiddling hacks Robert Wessel <robertwessel2@yahoo.com> - 2013-03-04 17:29 -0600
Re: bit twiddling hacks Johann Klammer <klammerj@NOSPAM.a1.net> - 2013-03-05 09:52 +0100
Re: bit twiddling hacks bob <bob@coolfone.comze.com> - 2013-03-05 07:45 -0800
Re: bit twiddling hacks Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-03-05 09:18 -0800
Re: bit twiddling hacks Robert Wessel <robertwessel2@yahoo.com> - 2013-03-05 12:48 -0600
Re: bit twiddling hacks "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-03-06 07:54 +0000
Re: bit twiddling hacks "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-03-06 07:58 +0000
Re: bit twiddling hacks Walter Banks <walter@bytecraft.com> - 2013-03-06 16:19 -0500
csiph-web