Connecting Tech Pros Worldwide Forums | Help | Site Map

How to test a bit in an integer?

Pierre Couderc
Guest
 
Posts: n/a
#1: Nov 13 '05
I want to test a bit in an integer and I have the SQL command :
SELECT myfiels,int FROM table WHERE (( int & 1)=1);
I want to get all the lines where int is even.
This instruction does not work in JET motor. I suppose that my syntax is
false somewhere.

What am I missing?

Thank you in advance.
Pierre Couderc

Arno R
Guest
 
Posts: n/a
#2: Nov 13 '05

re: How to test a bit in an integer?


> I want to get all the lines where int is even.

Try: Where int mod 2 = 0

--
Hope this helps
Arno R


Justin Hoffman
Guest
 
Posts: n/a
#3: Nov 13 '05

re: How to test a bit in an integer?


"Pierre Couderc" <pierre@couderc.ccNOSPAM> wrote in message
news:d2rn0c$1dqg$2@biggoron.nerim.net...[color=blue]
>I want to test a bit in an integer and I have the SQL command :
> SELECT myfiels,int FROM table WHERE (( int & 1)=1);
> I want to get all the lines where int is even.
> This instruction does not work in JET motor. I suppose that my syntax is
> false somewhere.
>
> What am I missing?
>
> Thank you in advance.
> Pierre Couderc[/color]


In general, if you want to test a bit, you would need to create your own
function in a module, e.g.

Public Function BitwiseAnd(lngOne As Long, lngTwo As Long) As Long
BitwiseAnd = lngOne And lngTwo
End Function

Then you can use this fnction in your query.

However, in your specific example, why not use the MOD operator such as
NewField: [MyField] MOD 2
which returns zero for even rows and one for odd rows.


Pierre Couderc
Guest
 
Posts: n/a
#4: Nov 13 '05

re: How to test a bit in an integer?


Thank you Justin, thank you Arno

- I need a solution at SQL level as in fact I am not in Access
- I have taken the sample of bit 2**0 but in fact I need any bit.

Mmm, in fact I think that this problem has no solution...

Pierre


Justin Hoffman a écrit :[color=blue]
> "Pierre Couderc" <pierre@couderc.ccNOSPAM> wrote in message
> news:d2rn0c$1dqg$2@biggoron.nerim.net...
>[color=green]
>>I want to test a bit in an integer and I have the SQL command :
>>SELECT myfiels,int FROM table WHERE (( int & 1)=1);
>>I want to get all the lines where int is even.
>>This instruction does not work in JET motor. I suppose that my syntax is
>>false somewhere.
>>
>>What am I missing?
>>
>>Thank you in advance.
>>Pierre Couderc[/color]
>
>
>
> In general, if you want to test a bit, you would need to create your own
> function in a module, e.g.
>
> Public Function BitwiseAnd(lngOne As Long, lngTwo As Long) As Long
> BitwiseAnd = lngOne And lngTwo
> End Function
>
> Then you can use this fnction in your query.
>
> However, in your specific example, why not use the MOD operator such as
> NewField: [MyField] MOD 2
> which returns zero for even rows and one for odd rows.
>
>[/color]
Lyle Fairfield
Guest
 
Posts: n/a
#5: Nov 13 '05

re: How to test a bit in an integer?


Pierre Couderc wrote:[color=blue]
> Mmm, in fact I think that this problem has no solution...[/color]

I am sure the problem has a solution. The beginning of the solution
would be, in my opinion, to make a very clear statement of the problem,
with examples.

When you talk of bit, we may think of a bit field. Then you talk of
integer. Whose integer? (I think this does not matter, but definitions
are very important to problem solving).

And then tools; what tools are available? Is it T-SQL? If so, what version?

A problem such as "I want to be able to return only records having
field (some field) with value such that value % 2 = 0 (the remainder on
division by 2 is zero) ... or that have the eighth bit set (up)" and I
want the solution to use T-SQL (MS-SQL 2000) only" is quite solvable by
many here.

Closed Thread