Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Bitwise AND for bigint

Author  Topic 

skumar2
Starting Member

3 Posts

Posted - 2007-10-04 : 02:52:54
Dear All,

I need to use bitwise AND operator on bigint data types. I came to know that bitwise AND operator supports only integer operands but in my case, operands values exceed than FFFFFFFF. Is there any way to use bitwise AND on 64 bit integers.

Thanking you in anticipation.
Regards,
Sorabh Arora

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-04 : 02:57:11
Really?
DECLARE	@t BIGINT,
@f BIGINT

SELECT @t = POWER(2.0, 40),
@f = POWER(2.0, 38) + POWER(2.0, 40)

SELECT @t AS t,
@f AS f,
@t & @f AS [And],
@t | @f AS [Or],
@t ^ @f AS [Xor],
CAST(POWER(2.0, 38) AS BIGINT) AS [2^38]

t f And Or Xor 2^38
------------- ------------- ------------- ------------- ------------- -------------
1099511627776 1374389534720 1099511627776 1374389534720 274877906944 274877906944

E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

skumar2
Starting Member

3 Posts

Posted - 2007-10-04 : 03:13:44
Actually, I was using a query something like this -

select * from table1 where module & 8589934590 <> 0

and it was failing .... and i realize that when i pass the number as hex, it gives correct result ... why its behaving in this way ..

Anyway ... i got the solution ...
Thanks for the help
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-04 : 03:15:30
What datatype is Module?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

skumar2
Starting Member

3 Posts

Posted - 2007-10-04 : 03:17:45
its bigint
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-04 : 03:18:26
Oh, what the heck...

select * from table1 where module & CAST(8589934590 AS BIGINT) > 0



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Dingemans
Starting Member

1 Post

Posted - 2013-10-02 : 04:41:11
Also, note that shift-left-logical operation can go wrong when starting with 2.0 (the Numeric datatype), rather than using the CAST of 2 to BIGINT.

select CAST(POWER(2.0,54) AS BIGINT), CAST(CAST(POWER(2.0,54) AS BIGINT) AS VARBINARY(MAX))
select CAST(POWER(2.0,55) AS BIGINT), CAST(CAST(POWER(2.0,55) AS BIGINT) AS VARBINARY(MAX))
select CAST(POWER(2.0,56) AS BIGINT), CAST(CAST(POWER(2.0,56) AS BIGINT) AS VARBINARY(MAX))
select CAST(POWER(2.0,57) AS BIGINT), CAST(CAST(POWER(2.0,57) AS BIGINT) AS VARBINARY(MAX))

select POWER(CAST(2 AS BIGINT),57) , CAST(POWER(CAST(2 AS BIGINT),57) AS VARBINARY(MAX))
Go to Top of Page
   

- Advertisement -