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.
    
        
            
                
                    
                        
                            
                                | Author | 
                                
                                 Topic  | 
                             
                            
                                    | 
                                         polob4385 
                                        Starting Member 
                                         
                                        
                                        1 Post  | 
                                        
                                        
                                            
                                            
                                             Posted - 2012-11-30 : 13:24:16
                                            
  | 
                                             
                                            
                                            | 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=144936903694469select (@something  / power(2,32)) & 0xFFFFFFFFThat 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 
                                     
                                    
                                    15732 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2012-11-30 : 13:33:37
                                          
  | 
                                         
                                        
                                          | http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/bitmask-handling-part-4-left-shift-and-right-shift.aspxYou'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.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     jimf 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    2875 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2012-11-30 : 13:35:48
                                          
  | 
                                         
                                        
                                          | the power function can only handle up 2 ^ 30 since it can only return an int (2 ^ 31)-1. So maybedeclare @something bigint;set @something=144936903694469select (@something / power(2,30))/4  & 0xFFFFFFFFJimEveryday I learn something that somebody else already knew  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     robvolk 
                                    Most Valuable Yak 
                                     
                                    
                                    15732 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2012-11-30 : 13:49:28
                                          
  | 
                                         
                                        
                                          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.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |