KBD

Keith Devens .com

Sunday, July 20, 2008 Flag waving
A language that doesn't affect the way you think about programming, is not worth knowing. – Alan Perlis
← Entry 1296Entry 1298 →

Daily link icon Friday, January 25, 2002

Entry 1297

Adam asks, "Is there some ultra-leet way given a 16 bit int with a single bit sent to determine which bit is set? That doesn't involve a 64k lookup table with a lot of zeros in it?"

Well, if only one bit is set it can only be one of 16 possible numbers, so the most expensive way to do it is to just do 16 comparisons. And if it happens to be the first one you test against, you only have to do one comparison Smiley

Is there any better way to do it? Hmm, since the number's going to be a power of two, I suppose you can do sort of a binary search on it, say "is it greater than 2^8? Yes, check 2^12, otherwise check 2^4", etc. Is there any better way than that? How many comparisons would that be?

← Entry 1296Entry 1298 →

Comments XML gif


Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

July 2008
SunMonTueWedThuFriSat
 12345
6789101112
13141516171819
20212223242526
2728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 2 posts

Recent comments XML

Spider solitaire

To answer an earlier question, I am​almost certain every game can be​beat. ...

Jared: Jul 16, 2:20pm

I hate Norton Antivirus

I HATE NORTON ANTIVIRUS IT SUCKS I​GOT AVG IT ROX! AGES TO DELETE​NORTON AN...

wade: Jul 15, 1:44am

Generated in about 0.121s.

(Used 8 db queries)

mobile phone