Jiri,
I haven't done much bit twiddling yet in AS3 but I think you were fast
already, but your i was being incremented and shifted.
Also i<8 would only get you bits 2,1,0
In binary that would be i<00001000
How about:
function getBit(var numb:int):int {
var bit:int=1;
var count:int=0;
if (numb==0 || numb>0x80) return -1; // error
while (bit & numb == 0) {
1 << bit;
count++;
}
return count;
}
John
Jiri 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?
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders