SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Bitwise AND for bigint
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

skumar2
Starting Member

3 Posts

Posted - 10/04/2007 :  02:52:54  Show Profile  Reply with Quote
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

Sweden
30218 Posts

Posted - 10/04/2007 :  02:57:11  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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"

Edited by - SwePeso on 10/04/2007 02:59:23
Go to Top of Page

skumar2
Starting Member

3 Posts

Posted - 10/04/2007 :  03:13:44  Show Profile  Reply with Quote
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

Edited by - skumar2 on 10/04/2007 03:16:59
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30218 Posts

Posted - 10/04/2007 :  03:15:30  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 - 10/04/2007 :  03:17:45  Show Profile  Reply with Quote
its bigint
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30218 Posts

Posted - 10/04/2007 :  03:18:26  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 Posts

Posted - 10/02/2013 :  04:41:11  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000