Hey,
not sure if it's faster, but this would work as well:
var i:Number = 32;
trace (Math.log(i)/Math.LN2);
returns bit number 5.
Lookuptable might be faster in this case.

greetz
JC



On Tue, Sep 15, 2009 at 10:04 AM, Jiri <jiriheitla...@googlemail.com> wrote:

> When i have a 8 bit int where only one of the bit can be 1, what is then
> the quickest way to get that bit position with value 1?
> Now I use this.
>
> function getBit():int{
>                        var tCount:int = 0;
>                        for (var i:int=0; i < 8; i++) {
>                          if (8 & (1 << i))     return i;
>                        }
>                        return 0;
>                }
> Can this be done faster?
>
> Jiri
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to