Page 1 of 2
number to bitshift

Posted:
Oct 9, 2002 @ 5:10pm
by Malmer

Posted:
Oct 9, 2002 @ 5:18pm
by angedelamort

Posted:
Oct 9, 2002 @ 5:21pm
by refractor

Posted:
Oct 9, 2002 @ 5:27pm
by Dave H

Posted:
Oct 9, 2002 @ 5:49pm
by Digby
If you're running on XScale you can use CLZ, then subtract the result from 31.
Otherwise, I'd probably perform a series of AND operations with mask and use a divide-and-conquer approach to find the set bit (test HIWORD/LOWORD, test HIBYTE/LOBYTE, test HINIBBLE/LONIBBLE, etc.). This will get you the result after 5 ANDs and 5 comparisons. It's not one line of code, but it's probably faster than the other methods suggested.

Posted:
Oct 9, 2002 @ 6:08pm
by refractor

Posted:
Oct 9, 2002 @ 6:56pm
by Malmer

Posted:
Oct 9, 2002 @ 6:59pm
by Malmer

Posted:
Oct 9, 2002 @ 7:17pm
by Guest

Posted:
Oct 9, 2002 @ 10:54pm
by Malmer
If it is the software will create a huge disruption in space time continuum, which will lead to the ultimate destruction of the universe and everything in it, except for the duracell bunny. It keeps going and going forever and ever...
...Or maybe not...

Posted:
Oct 9, 2002 @ 11:31pm
by refractor
Here's another potential issue - what happens if b is
negative?
As it's signed, the shift will be arithmetic, thus it'll end up as -1, never 1... giving us the infinite loop until the bunny's batteries run out


Posted:
Oct 9, 2002 @ 11:49pm
by Malmer
What if the bunny is connected to a 12V adaptor...then we have serious issues with the world collapsing and stuff...

Posted:
Oct 10, 2002 @ 2:13am
by sponge
Your forgetting all about the Bunny factor D, which states that to sucessfully power a bunny, you will need a cold fusion reactor, so keeping the bunny powered after the break is merely a dream.

Posted:
Oct 10, 2002 @ 2:46pm
by Malmer
Ouch forgot that...so the problem will basically cause the entire universe to collapse, and that's it...?
maybe I should run my app in debug mode first, so I can catch the exception before the world is destroyed.

Posted:
Apr 12, 2003 @ 3:48am
by Dan East
Has anyone tried the code Refractor posted? I can't get it to return proper results.
Dan East