Обсуждение: bitwise AND?

Поиск
Список
Период
Сортировка

bitwise AND?

От
Vince Vielhaber
Дата:
Do we have any kind of bitwise AND?   
  select foo from bar where (foo AND 2);  

Doesn't work with ints.

Vince.
-- 
==========================================================================
Vince Vielhaber -- KA8CSH    email: vev@michvhf.com    http://www.pop4.net128K ISDN from $22.00/mo - 56K Dialup from
$16.00/moat Pop4 Networking       Online Campground Directory    http://www.camping-usa.com      Online Giftshop
Superstore   http://www.cloudninegifts.com
 
==========================================================================





Re: bitwise AND?

От
Lamar Owen
Дата:
Vince Vielhaber wrote:
> Do we have any kind of bitwise AND?

Non directly.
>    select foo from bar where (foo AND 2);

Ok, you _can_ do this; it's just a big pain to do so.

First, decompose any bitwise AND into TESTBIT and logical AND
operators.  TESTBIT is the same as AND, just having a single bit set.

In your example, AND 2 is already a single bit.  But, I'm going to
illustrate the general solution: suppose we have AND 7 -- decompose into
(foo TESTBIT 4) AND (foo TESTBIT 2) AND (foo TESTBIT 1).

Now, rewrite that to:
((foo % 8)/4)*((foo % 4)/2)*((foo % 2)/1) -- if the result is greater
than zero, the logical AND is true.

For bitwise OR, substitute integer + for integer * above.

For your case, write the query:

select foo from bar where ((foo % 4)/2)>0

AFAIK and have tested, that should work the way you think it should. (I
knew those exercise in Z80 machine language would come in handy! :-))
--
Lamar Owen
WGCR Internet Radio
1 Peter 4:11