Re: x >> x

From: d. hall (dhall@OOI.NET)
Date: 07/25/98


>>>>> thus on Fri, 24 Jul 1998 23:01:13 EDT, I wrote:

> okay, i just need a lil help here :)
> i need to convert a (1 >> 7) [which is 128] into
> 7...but i have like a variable 128 that i got from
> 1 >> 7, and i need to convert it back into 7...any help?

I've seen a few solutions listed.

Are you trying to make a function that takes a bitvector and returns which
bit is set?

Or you just trying to turn 128 into 7?

x = (1 >> 7);
y = 1;

while (y < 32) {
        if (2 ^ y == x) {
                return y;
        }
}

All (1 >> 7) is 2 to the 7th power.

If you're checking which is the lowest bit set, check out sprintbit() in
utils.c to see how you could do it.

d.


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST