[Nottingham] A Little Coding Gem

Martin martin at ml1.co.uk
Thu Nov 15 23:01:11 UTC 2012


On 15/11/12 22:09, Martin wrote:
[---]
> 
> Yep, that reverses the bits in a 32-bit int.

For the Haskell lovers, I rather like this method even if it is
hideously inefficient compared to the powers-of-two shift and combine:

"The idea is simple. Divide up input by half and swap the two halves,
continue till it it reaches single bit."

http://stackoverflow.com/questions/746171/best-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c/9041652#9041652




> As to *why* you might want that... Well, I can't think of a case other
> than for reverse sorting an int shift register of boolean flags of some
> event for whatever reason.
> 
> We have a mix of "big endian" and "little endian" systems, however that
> is of little concern being as whatever endian-ness is untangled at
> whatever communications or storage interface is used.
> 
> So... What would that usefully be used for?...

Good for musing further...


Good fun!

Cheers,
Martin


-- 
- ------------------ - ----------------------------------------
-    Martin Lomas    - OpenPGP (GPG/PGP) Public Key: 0xCEE1D3B7
- martin @ ml1 co uk - Import from   hkp://subkeys.pgp.net   or
- ------------------ - http:// ml1 .co .uk/martin_ml1_co_uk.gpg



More information about the Nottingham mailing list