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
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
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
Paul Andrews wrote:
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
Thnx, i tought that there would be some kind of smart bitwise operation
to do that. This will do fine. Cheers.
Jiri
Paul Andrews wrote:
Paul Andrews wrote:
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
Another option:
function test(value:int):int {
// just to be safe...
value = value 0xff;
switch(value) {
case 0x01: return 0;
case 0x02: return 1;
case 0x04: return 2;
case 0x08: return 3;
case 0x10: return 4;
case 0x20: return 5;
case 0x40: return 6;
case 0x80: return
Juan Pablo Califano wrote:
Another option:
function test(value:int):int {
// just to be safe...
value = value 0xff;
switch(value) {
case 0x01: return 0;
case 0x02: return 1;
case 0x04: return 2;
case 0x08: return 3;
case 0x10: return 4;
case 0x20: return 5;
case 0x40:
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 i8 would only get you bits 2,1,0
In binary that would be i1000
How about:
function getBit(var numb:int):int {
var bit:int=1;
var count:int=0;
if
I think his i 8 was valid as the i is used for the shift, not the value...
The only thing that might be faster is using i-- rather than i++ - for
some reason decrementing through a loop is suppsoed to be faster.
Glen :)
John McCormack wrote:
Jiri,
I haven't done much bit twiddling yet in
It's a little curious loop!
i=0
i shifted = 0
i++ gives = 1 binary 0001
i shifted = 2 binary 0010
i++ gives i=3 binary 0011
i shifted=6 binary 0110
i++ gives i= 7 binary 0111
i shifted=14 binary 1110
End of loop because i=8
i++ gives i= 15 binary
Can't confirm your findings right now, and also wonder which loop you
are talking about. My initially posted one?
function getBit():int{
var tCount:int = 0;
for (var i:int=0; i 8; i++) {
if (8 (1 i))return i;
}
return 0;
Cheers.
Jiri
Paul Andrews wrote:
Juan Pablo Califano wrote:
Another option:
function test(value:int):int {
// just to be safe...
value = value 0xff;
switch(value) {
case 0x01: return 0;
case 0x02: return 1;
case 0x04: return 2;
case 0x08: return 3;
case 0x10: return 4;
12 matches
Mail list logo