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
 General SQL Server Forums
 New to SQL Server Programming
 bitshifting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

polob4385
Starting Member

USA
1 Posts

Posted - 11/30/2012 :  13:24:16  Show Profile  Reply with Quote
I have a long for example 144936903694469 and in java i have (int)(id>> 32) & 0xFFFFFFFF. I should get returned 3375 . so I wrote this..

declare @something bigint;
set @something=144936903694469
select (@something / power(2,32)) & 0xFFFFFFFF

That seems wrong but not sure what I need to do or if I am missing something. I did Google it and thats as much as i came up with.

Ideas? Thank you.

robvolk
Most Valuable Yak

USA
15676 Posts

Posted - 11/30/2012 :  13:33:37  Show Profile  Visit robvolk's Homepage  Reply with Quote
http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/bitmask-handling-part-4-left-shift-and-right-shift.aspx

You're better off avoiding bit shifting in SQL Server. If you absolutely have to support it your best bet is to create a CLR function for it.
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 11/30/2012 :  13:35:48  Show Profile  Reply with Quote
the power function can only handle up 2 ^ 30 since it can only return an int (2 ^ 31)-1. So maybe

declare @something bigint;
set @something=144936903694469
select (@something / power(2,30))/4 & 0xFFFFFFFF


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

robvolk
Most Valuable Yak

USA
15676 Posts

Posted - 11/30/2012 :  13:49:28  Show Profile  Visit robvolk's Homepage  Reply with Quote
If you cast it as bigint, you can do:
select POWER(cast(2 as bigint),62)
However the bitwise operators only work up to 32 bits.
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.03 seconds. Powered By: Snitz Forums 2000