On 2004-05-02 at 23:07 PDT, Michal Guerquin wrote:
>I can implement my own, or use a sequence of existing
>bitwise operations like (~(a&b))&(a|b), but neither
>option sounds as efficient a native opcode in the
>virtual machine.
Well, I'm back! :)
After several hours of bug hunting, I think I may have
found a bug (or feature) in SQLite. I get seemingly
incorrect results on some bitwise operations.. please
corret me if I'm wrong somewhere.
First, the VM seems to recognize the numbers in this
expression just fine:
sqlite> .explain
sqlite> explain SELECT
(~(3733753&3062762))&(3733753|3062762)|(~(535705&535179))&(535705|535179);
addr opcode p1 p2 p3
---- ------------ ---------- ---------- -----------------------------------
0 ColumnName 0 1 (~(3733753&3062762))&(3733753|30627
1 ColumnName 1 0 NUMERIC
2 Integer 3733753 0 3733753
3 Integer 3062762 0 3062762
4 BitAnd 0 0
5 BitNot 0 0
6 Integer 3733753 0 3733753
7 Integer 3062762 0 3062762
8 BitOr 0 0
9 BitAnd 0 0
10 Integer 535705 0 535705
11 Integer 535179 0 535179
12 BitAnd 0 0
13 BitNot 0 0
14 BitOr 0 0
15 Integer 535705 0 535705
16 Integer 535179 0 535179
17 BitOr 0 0
18 BitAnd 0 0
19 Callback 1 0
20 Halt 0 0
But when I perform the operation:
sqlite> SELECT
(~(3733753&3062762))&(3733753|3062762)|(~(535705&535179))&(535705|535179) AS x;
x
----
1555
The result does not match the result I expect, as seen
in this code:
#include <stdio.h>
int main(void)
{
int a = 3733753;
int b = 3062762;
int c = 535705;
int d = 535179;
int x = (~(3733753&3062762))&(3733753|3062762)|(~(535705&535179))&(535705|535179);
int y = (~(a&b))&(a|b)|(~(c&d))&(c|d);
int z = (a^b)|(c^d);
printf("%d\n", x);
printf("%d\n", y);
printf("%d\n", z);
}
x = y = z = 1459987 is the correct answer.
In binary notation, I see:
1459987 = 101100100011100010011
1555 = 000000000011000010011
So, it looks like only some of the bits are being
returned as the result in SQLite.. the rest are 0. Why
is this?
-Michal
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]