Binary AND in Query (1 Viewer)

jan@BRU

Registered User.
Local time
Today, 02:08
Joined
Jul 18, 2007
Messages
39
Hello folks,

I have a short question with respect to the usage of the AND operator in queries.

in VBA, "AND" can be used to make to make a bit by bit comparison of integer numbers, e.g.

? cbyte(47) and cbyte(254) yields 46

It's precisely this function that I would like to reproduce in a query field. However if I include the very same expression:


Expr1: cbyte(47) And cbyte(254)

or something more useful like:

Expr1: cbyte(
.[IntegerField]) And cbyte(254)

I get invariably "True" or -1 as a result of this field.

Can anybody help, what I need to do get the result of the bitwise operation without the need to call a customized vba function from the query.

Many thanks

Jan

PS: cbyte() only used for clarity ... straight numbers yield the same results
 

stopher

AWF VIP
Local time
Today, 10:08
Joined
Feb 1, 2006
Messages
2,395
To quote Allen Browne: " bitwise operations work only in VBA. In other contexts, you get a logical comparison - the wrong result if you expected a bitwise operation." Ref

So I guess the way round this is to write a function in VBA and then use it in your query.

hth
Chris
 
Last edited:

Brianwarnock

Retired
Local time
Today, 10:08
Joined
Jun 2, 2003
Messages
12,701
I would question the use of this as

cbyte(2) and cbyte(2)
cbyte(3) and cbyte(2)
cbyte(11) and cbyte(2)

for example all yield 2 as the result, is this type of thing acceptable for what you want?

Brian
 

jan@BRU

Registered User.
Local time
Today, 02:08
Joined
Jul 18, 2007
Messages
39
Brian,
yes this is perfectly what I want.

2: 00000010
3: 00000011
11: 00001011

applying a bit-wise AND 2:

2: 00000010

should yield a 2 in all case, as, it tests, whether in 2, 3, 11, the second but last significant bit is set (which is the case for all of 2, 3, and 11).

Guess, I will have to resort to a function for the query, which horribly slows down the query.... :mad:

Jan
 

jan@BRU

Registered User.
Local time
Today, 02:08
Joined
Jul 18, 2007
Messages
39
Stopher, would you mind repasting the link ...

Many thanks

jan
 

Users who are viewing this thread

Top Bottom