home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!iWarp.intel.com|inews!pinkas
- From: pinkas@caraway.intel.com (Israel Pinkas)
- Newsgroups: comp.programming
- Subject: Re: finding 1st one in integer
- Message-ID: <PINKAS.92Jul21181341@caraway.intel.com>
- Date: 22 Jul 92 01:13:41 GMT
- References: <Brqu3F.1J4@undergrad.math.waterloo.edu>
- <1992Jul21.173805.12045@bcrka451.bnr.ca>
- <1992Jul21.150033@is.morgan.com> <1992Jul21.205127.23216@wdl.loral.com>
- Sender: news@inews.intel.com
- Organization: Software Technologies, INTeL Corporation, Santa Clara, CA
- Lines: 27
- In-reply-to: mab@wdl39.wdl.loral.com's message of 21 Jul 92 20:51:27 GMT
-
- mab@wdl39.wdl.loral.com (Mark A Biggar) writes:
-
- This is no problem as i^(i-1) produces a value consisting on just the least
- sigfinicant bit in i
-
- Not quite. i-1 zeros the lease significant bit of i, but it sets all the
- lower bits. Exclusive ORing with i zeros all but the least significant 1
- bit, but it sets all the lower bits.
-
- (i^(i-1))>>1+1 should do the trick for all values of i. i should be
- defined as an unsigned entity to avoid problems. Constant time, four
- operations.
-
- i i-1 i^(i-1) (i^(i-1))>>1 (i^(i-1))>>1+1
- ------------------------------------------------------
- 000001 000000 000001 000000 000001
- 000010 000001 000010 000001 000010
- 000011 000010 000001 000000 000001
- Note 000110 000101 000011 000001 000010
- 101100 101011 000111 000011 000100
- 101010 101001 000011 000001 000010
-
- -Israel
- --
- Disclaimer: The above are my personal opinions, and in no way represent
- the opinions of Intel Corporation. In no way should the above be taken
- to be a statement of Intel.
-