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
 Development Tools
 ASP.NET
 C# >> operator

Author  Topic 

olay80
Yak Posting Veteran

62 Posts

Posted - 2005-05-27 : 05:04:59
hey guys,

can anyone help with the >> shift operator and tell me how they work i read some examples but i didn't get it..

thanx,
Oliver

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-05-27 : 05:30:42
using the windows calculator:
number 10 in binary is 1010
say you right shift it by one bit you get:
0101 which is 5
if you left shift by one bit you get
10100 which is 20

any clearer?

so basicaly this is the fastest way of division or multiplication by 2



Go with the flow & have fun! Else fight the flow
Go to Top of Page

olay80
Yak Posting Veteran

62 Posts

Posted - 2005-05-27 : 08:01:30
thanx alot
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-05-27 : 09:52:50
As a side note be careful when shifting because of data size.
For instance, because types have a max / min size then shifts
and the results can become the same:

int i;
i = 100;

i << 1;
printf("%d", i);

i << 33;
printf("%d", i);

both yield same results


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page
   

- Advertisement -