473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

bitwise operations

All,

I have not visited Access for a while, and I am drawing a blank on how
to search/sort a column of data (integer) for/on a particular bit
pattern. Actually, a SQL example would be great.
TIA,
Bill

May 11 '06 #1
3 9493
My !!!!vague!!!! recollection is that one must use OLEDB to effect
bitwise operations in Access/Jet SQL regardless of the Ansi 92 setting.
ADODB is of course an OLEDB route, or vehicle.

As I recall the first of these works correctly, while the second does
not:

Private Sub ADODBForBitWiseQuery()
Dim r As ADODB.Recordset
With CurrentProject.Connection
Set r = .Execute("SELECT ID, ID BXOR 2 as IDBXORedWith2 from
Table4")
MsgBox r.Collect(0) & ":" & r.Collect(1) & ":" &
CStr(r.Collect(0) Xor 2)
End With
End Sub

Private Sub DAOForBitWiseQuery()
Dim r As DAO.Recordset
With DBEngine(0)(0)
Set r = .OpenRecordset("SELECT ID, ID XOR 2 as IDXORedWith2
from Table4")
MsgBox r.Collect(0) & ":" & r.Collect(1) & ":" &
CStr(r.Collect(0) Xor 2)
End With
Set r = Nothing
End Sub

You could test them by running the SQL on any table with a whole number
ID field, changing the name of the table. Of course, you could use
another field (name) as well.

But I have not studied this extensively. It is entirely possible that a
DAO solution will be posted.

May 11 '06 #2
My !!!!vague!!!! recollection is that one must use OLEDB to effect
bitwise operations in Access/Jet SQL regardless of the Ansi 92 setting.
ADODB is of course an OLEDB route, or vehicle.

As I recall the first of these works correctly, while the second does
not:

Private Sub ADODBForBitWiseQuery()
Dim r As ADODB.Recordset
With CurrentProject.Connection
Set r = .Execute("SELECT ID, ID BXOR 2 as IDBXORedWith2 from
Table4")
MsgBox r.Collect(0) & ":" & r.Collect(1) & ":" &
CStr(r.Collect(0) Xor 2)
End With
End Sub

Private Sub DAOForBitWiseQuery()
Dim r As DAO.Recordset
With DBEngine(0)(0)
Set r = .OpenRecordset("SELECT ID, ID XOR 2 as IDXORedWith2
from Table4")
MsgBox r.Collect(0) & ":" & r.Collect(1) & ":" &
CStr(r.Collect(0) Xor 2)
End With
Set r = Nothing
End Sub

You could test them by running the SQL on any table with a whole number
ID field, changing the name of the table. Of course, you could use
another field (name) as well.

But I have not studied this extensively. It is entirely possible that a
DAO solution will be posted.

May 11 '06 #3
VBA supports bit operatations, such as converting to upper case (turning a
bit on) with:
vbKeyA OR &H20
or forcing to lower case (turning a bit off) with:
97 AND NOT &H20

Before Access 2000, JET SQL never supported bit operations. The new binary
JET SQL operators are not well documented, but they start with B, e.g. BAND
for Binary AND, BOR of Binary OR, etc. Trouble is, this only works if you
run the query under ADO. Since the Access query interface uses DAO, you
cannot do this in a normal Access query, only programmatically. This example
flips all the bits in the integer field MyIntFlip:

Function TestBnot() AS Long
Dim strSql As String
strSql = "UPDATE MyTable SET MyIntFlip = BNOT MyInt WHERE MyIntFlip Is
Not Null;"
CurrentProject.Connection.Execute strSql, lngKt
TestBnot = lngKt
End Function

A workaround if you need it in DAO or in the interface or Access 97 is to
call VBA functions to perform the binary operations. This example tests the
result of an AND operation on two bytes, so you can pass the fields into the
function and display the result by typing this calculated field into your
query:
MyResult: BitwiseAndByte([Byte1], [Byte2])

Function BitwiseAndByte(varByte1 As Variant, varByte2 As Variant) As Boolean
On Error Resume Next
BitwiseAndByte = CByte(vByte1) And CByte(vByte2)
End Function

(The function accepts variants to support non-required fields.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"bill" <wg****@draper.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...

I have not visited Access for a while, and I am drawing a blank on how
to search/sort a column of data (integer) for/on a particular bit
pattern. Actually, a SQL example would be great.

May 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Randell D. | last post by:
Why would one use bitwise operators? I can program in various languages in some shape or form (C++, PHP, some scripting) and I've heard/seen bitwise operators before, but never understood why...
6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
8
by: Paul E Collins | last post by:
Suppose I have a few Keys objects: Keys k1 = Keys.V; // V Keys k2 = Keys.Control | Keys.V; // Ctrl+V Keys k3 = Keys.Shift | Keys.J; // Shift+J I need to determine which of these include the...
9
by: Christopher Weaver | last post by:
I know that the bitwise AND of 8 and 4 will return 0 or false and the bitwise AND of 8 and 9 will return 1 or true but I don't know how to write the synax for it in C#. I have a value that ranges...
10
by: Emilio | last post by:
Do I use 'or' for bitwise operations where in c# I use | ?
4
by: AMDRIT | last post by:
Gang, I always get confused when it comes to 1's and 0's. I would like to perform a bitwise operation on a value based on checked boxes. Am I doing this right? assuming...
3
by: shdwsclan | last post by:
I am native to various languages but bitwise operators just kill me. I see how much I take object oriented languages for granted. I like all the other c derivitives but ANSI C is making me loose my...
45
by: Carramba | last post by:
Hi! I now that I can't do straight forward any bitwise operation on float (double etc..). But I wondering what is the easiest/best way to do this? I was thinking if I have float x=1.1111 so I can...
29
by: Carl Banks | last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this is just talk.) Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not...
8
by: Daniel Gutson | last post by:
Hi, I just wanted to share another library for doing type-safe bitwise operations in C++: http://bitwise-enum.googlecode.com I found it useful, so hopefully it'll be for somebody else as well....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.