Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binary operations in Access 1

Status
Not open for further replies.

herbivorous

Technical User
Mar 28, 2002
32
0
0
US
My question in micro is whether within Access there is an easy way to do a binary AND of two numbers -- to see if the two numbers share any bits that are ON (1).

The bigger picture is this -- I have a table of people with a linked table that indicates areas of interest. These areas of interests are stored in another table with an autonumber ID. Right now, there are 27 possible areas of interest, numbered 1-27. A person may have any number of areas of interest.

I would like to be able to filter for these areas of interest without having to link the two tables. Domain aggregate functions can probably do the work, but I'm afraid that this would be messy and slow. I'd like to generate a binary representation of a given person's areas of interest where bit x = 1 if a person is interested in the area whose ID number is x. I'd then generate a similar binary to represent the areas of interest for which I am searching -- 2 or 7 or 9 (...1010000100) which could be quickly compared to generate a list of people who are interested in one or more areas for which I'm searching.

If you follow me. . .

Perhaps there's a better way to do this and I'm charging down a blind alley, though it seems to me that all I want is a simple binary AND, which sure doesn't seem too much to ask.
 
Hi herbivorous,

all I want is a simple binary AND

.. so all you have to use is a simple AND, for example

Code:
Dim i As Integer, j As Integer
i = 100
Code:
 ' Binary 1100100
Code:
j = 98
Code:
 ' Binary 1100010
Code:
Msgbox i And j
Code:
 ' Gives 96 = Binary 1100000
Code:

Enjoy,
Tony
 
Thanks -- problem I was having was looking for it in Access rather than in VB. I need to use it on a query grid, but once I found it in VB I was able to write the world's simplest function to give me the use of it in the query.

Thanks for your help.
 
The 'standard' representation for 'packing' uses the simple fact of powers of 2. e.g.

2 ^ 0 = 1
2 ^ 1 = 2
2 ^ 2 = 4
2 ^ 3 = 8
2 ^ 4 = 16
[tab]o
[tab]o
[tab]o
[tab]o
2 ^ 27 = 134217728

In a "Long", each value is represented by a single "Bit". Each cpmbination of bits (rather obviously) is unique. so the bitwise values may be added to arrive at the set of values being represented. comparision of pairs of the values depends on the application, but simplistic manipulation (matching) is easily accomplished with XOR. Matching of subsets is usually done with successive XOR's, but many other approaches are possible.




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top