Ken wrote:
I've created a table and need to perform some bitwise operations against one of
the fields. I find that 0 is returned back from the select.
Also I'd like to add a feature request such that sqlite would understand
'0xffff' syntax and convert a hex string into a number. Or at least a function
so that the sql code is more readable.
Example follows:
Thanks,
Ken
Sqlite version is 3.5.4
create table x (val integer );
insert into x values (10083463462913);
select to_hex(val) from x; (note to_hex is my own function).
to_hex(val)
0x92bbd420001
I want to strip off the 0001 portion. So and it with 18446744073709486080
which is 0xffffffffffff0000
select val&18446744073709486080 from x;
val&18446744073709486080
0
select (val&18446744073709486080) from x;
(val&18446744073709486080)
0
Ken,
Sqlite uses signed 64 bit integer values, so your literal
18446744073709486080 is too large and it is approximated as a floating
point value 1.84467440737095e+19.
You could use the corresponding signed value -65536, but a better way to
generate such a mask is to shift a -1 (all F's) value to insert the
required zero bits.
select 10083463462913 & (-1 << 16);
10083463462912
This is the correctly masked value.
HTH
Dennis Cote
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------