
bitwise left shift operator
As far as I understand , there isn't a native biwise left shift operator in
Tsql. Such as in C++ or C# i.e << .
Would anyone be able to advise me on how to simulate the bitwise left 
shift  operator in TSQL.
Thanks

Jack Vamvas
___________________________________
Need an IT job? http://www.ITjobfeed.com

Re: bitwise left shift operator
> Would anyone be able to advise me on how to simulate the bitwise left 
> shift  operator in TSQL.
Just multiply the value by 2.
Razvan

Re: bitwise left shift operator
Thanks , just so I can be clear , if I wanted to do a left shift operator
by 2 , (on a integer)such as : 43234 << 2, would I multiply by 2 to
get the leftshiftby 1 and then multiply by 2 again to left shift again.
?

Jack Vamvas
___________________________________
Need an IT job? http://www.ITjobfeed.com
"Razvan Socol" wrote in message
news:1183296668.852308.57090@g4g2000hsf.googlegroups.com...
>> Would anyone be able to advise me on how to simulate the bitwise left 
>> shift  operator in TSQL.
>
> Just multiply the value by 2.
>
> Razvan
>

Re: bitwise left shift operator
To achieve @i << @j, the following may be what you're after:
SELECT @i * POWER(2, @j)
* Note that this might result in an overflow.
However, since there's no native support for bit shifting and you are trying
to mimic its behavior, it would be helpful if you provided more info
regarding what exactly you are after. But before that, is it really bit
shifting that you are after or are you trying to model something and think
that bit shifting can help?
If bit shifting IS what you need, do you know which type of bit shifting you
really need (e.g., arithmetic/logical)?
There are some pitfalls with bit shifting and a more accurate definition of
the exact behavior you are after would be helpful in providing a solution
without bugs.
See the following articles for more info:
http://en.wikipedia.org/wiki/Bitwise_shift#Bit_shifts
http://en.wikipedia.org/wiki/Arithmetic_shift
http://en.wikipedia.org/wiki/Logical_shift

BG, SQL Server MVP
www.SolidQ.com
www.InsideTSQL.com
"Jack Vamvas" wrote in message
news:zOOdnduT0uMNMBrbnZ2dnUVZ8qugnZ2d@bt.com...
> Thanks , just so I can be clear , if I wanted to do a left shift operator
> by 2 , (on a integer)such as : 43234 << 2, would I multiply by 2 to
> get the leftshiftby 1 and then multiply by 2 again to left shift
> again. ?
>
> 
>
> Jack Vamvas
> ___________________________________
> Need an IT job? http://www.ITjobfeed.com
>
>
>
>
> "Razvan Socol" wrote in message
> news:1183296668.852308.57090@g4g2000hsf.googlegroups.com...
>>> Would anyone be able to advise me on how to simulate the bitwise left 
>>> shift  operator in TSQL.
>>
>> Just multiply the value by 2.
>>
>> Razvan
>>
>
>

Re: bitwise left shift operator
On 1 Jul, 14:35, "Jack Vamvas" wrote:
> Thanks , just so I can be clear , if I wanted to do a left shift operator
> by 2 , (on a integer)such as : 43234 << 2, would I multiply by 2 to
> get the leftshiftby 1 and then multiply by 2 again to left shift again.
> ?
>
I'd like to understand just why you feel the need to do bit
manipulation in SQL. For a number of reasons any form of bit
representation in a SQL database is probably not a good idea. It is
frequently the case that tricky problems encountered in SQL are due to
design errors so maybe if you explain some more someone can suggest a
different approach to the problem.

David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
