Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

access bitwise AND operator?

Posted on 2000-03-20
10
Medium Priority
?
1,703 Views
Last Modified: 2008-01-09
Hi Folks,

does access have a bitwise AND operator?

eg:

1 AND 2 = 0 (001 AND 010 = 000)
1 AND 3 = 2 (001 AND 011 = 010)
7 AND 1 = 1 (111 AND 001 = 001)
5 AND 2 = 0 (101 AND 010 = 000)
4 AND 0 = 0 (100 AND 000 = 000)
etc.

on testing, access gives:

1 AND 2 = 1
1 AND 3 = 1
7 AND 1 = 1
5 AND 2 = 1
4 AND 0 = 0

which suggests that the arguments are treated as >0 = TRUE

cheers.

0
Comment
Question by:meverest
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 22

Expert Comment

by:ture
ID: 2639417
meverest,

Which version of Access are you using? In Access 97 and Access 2000, bitwise operations ARE supported. Perhaps also in previous versions, but I have not been able to test that.

Try this in the "debug" or "immediate" window:

Print 1 and 2
Print 1 and 3
Print 7 and 1
Print 5 and 2

Ture Magnusson
Karlstad, Sweden
0
 
LVL 37

Author Comment

by:meverest
ID: 2639698
it is access97 and i want to do it in a query (from SQL view)

does this make a difference?  i am not familiar with vb macro/scripts.

cheers.
0
 
LVL 15

Expert Comment

by:cquinn
ID: 2639929
From Access help file:

The And operator also performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result
 according to the following table:

If bit in expression1 is      And bit in expression2 is      The result is
0      0      0
0      1      0
1      0      0
1      1      1
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 37

Author Comment

by:meverest
ID: 2642150
thanks to all thus far.

all these points seem to suggest that access already does what i want, but for some unknown reason, many tests prove exactly the opposite.

take this test as an example:

i make a table 'data' that contains two columns 'a' and 'b', then i populate the table like this:

a b
1 2
2 2
3 2
4 2
5 2
6 2
7 2
8 2

and i create a new query:

select a from data where a AND b

i expect this output:

2, 3, 6, 7

but in fact i get:

1, 2, 3, 4, 5, 6, 7, 8

which suggests (as per previous comment) that access thinks that <= 0 is 'false' and that >= 1 is 'true'

regards.
0
 
LVL 6

Expert Comment

by:blakeh1
ID: 2642167
to set a bit use
the OR operator
to turn a bit off use AND NOT

example turn on the first bit use
me.Bitvalue=(me.bitvalue OR 2^0)
  to turn it off use
me.Bitvalue=(me.bitvalue AND NOT 2^0)

to get the bit value you can use something like

me.chkbox=((Me.Bitvalue And 2^0) = 2^0)


0
 
LVL 37

Author Comment

by:meverest
ID: 2642269
thanks blakeh1,

but i do not understand how i apply this technique to an (access) sql query?

please see my previous comment defining what i am trying to do - this is what i need.

regards.
0
 
LVL 6

Accepted Solution

by:
blakeh1 earned 200 total points
ID: 2642302
to get the values of 2,3,6,7
yo must create a new field in the query and use
test: (([a]\[b]) Mod 2) and for it's criteria use 1

the sql would be

SELECT a, (([a]\[b]) Mod 2) AS test
FROM data
WHERE ((((([a]\[b]) Mod 2))=1));
0
 
LVL 37

Author Comment

by:meverest
ID: 2642354
cool!

that works just fine,  thanks :)
0
 
LVL 37

Author Comment

by:meverest
ID: 2642417
hmm, i jumped the gun a bit there...

it works only for that specific data set, but not as a general rule for (a AND b)

dang!

if you can't offer any more suggestions, i guess that i will need to post a new question :(

cheers.
0
 

Expert Comment

by:GuyCowley
ID: 8648527
I had this same problem and solved at with a function:

' Returns bitwise a and b
Public Function fnAND(a As Byte, b As Byte) As Byte

    fnAND = a And b

End Function
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question