Thread: Bits and bytes- Please help.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312
    Quote Originally Posted by quzah View Post
    Yeah, I can do it in 1 with a lookup table.
    But your lookup table will waste memory, as it will have 256 entries.

    Here's a proof-of-concept code that does (not quite) exactly what the OP wanted to achieve:

    Code:
    int ffc(char c)
    {
    	c = ~c;
    
    	static const char debruijn[8] = {0, 1, 2, 4, 7, 3, 6, 5};
    	return debruijn[((c & -c) * 23) >> 5];
    }
    It is full of magic numbers and without reading the HOWTO, it will be very hard to understand what the code is doing.

    Greets,
    Philip
    Last edited by Snafuist; 05-28-2009 at 01:28 PM.
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. SDLKey to ASCII without unicode support?
    By zacs7 in forum Game Programming
    Replies: 6
    Last Post: 10-07-2007, 03:03 AM
  3. trying to convert system bytes into bits and nibbles.
    By kraze_505 in forum C Programming
    Replies: 11
    Last Post: 01-25-2006, 02:27 AM
  4. Bits & Bytes
    By C of Green in forum C++ Programming
    Replies: 8
    Last Post: 06-21-2002, 06:50 PM
  5. Bits, Bytes & Nibbles!
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-13-2001, 10:22 PM