473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Right shift operator

ERE
Pardon me if this has been asked a million times -- but I thought that
because of generics, the right shift operator was supposed to change with C#
2.0. I thought it was supposed to change from ">>" to "> >", to distiguish
it from nested generics.

But I've been using VS2005, and when I put in the new syntax I get an error
message, whereas the old syntax, as shown in the following code continues to
work fine. What am I missing?

Thanks,
Dan

------------------
static void Main( )
{
for (int i = 32; i > 0; )
{
i = i >> 1;
Console.WriteLine("Value: {0}", i);
}
}
Dec 18 '05 #1
3 2600
ERE <ea*******@ma.ultranet.com> wrote:
Pardon me if this has been asked a million times -- but I thought that
because of generics, the right shift operator was supposed to change with C#
2.0. I thought it was supposed to change from ">>" to "> >", to distiguish
it from nested generics.

But I've been using VS2005, and when I put in the new syntax I get an error
message, whereas the old syntax, as shown in the following code continues to
work fine. What am I missing?


The right shift operator itself hasn't been changed in terms of what
you write. It's been changed in terms of what one part of the compiler
gives to the other. Instead of the parser recognising one token of
">>" it recognises two tokens, each of which is ">".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 18 '05 #2
On Sat, 17 Dec 2005 23:33:57 -0800, "ERE" <ea*******@ma.ultranet.com>
wrote:
Pardon me if this has been asked a million times -- but I thought that
because of generics, the right shift operator was supposed to change with C#
2.0. I thought it was supposed to change from ">>" to "> >", to distiguish
it from nested generics.

But I've been using VS2005, and when I put in the new syntax I get an error
message, whereas the old syntax, as shown in the following code continues to
work fine. What am I missing?

Thanks,
Dan

------------------
static void Main( )
{
for (int i = 32; i > 0; )
{
i = i >> 1;
Console.WriteLine("Value: {0}", i);
}
}


There has been no change to what you type, right-shift is still ">>"
and right-shift assignment is still ">>=". There has been a change to
the underlying grammar to prevent the compiler treating the >> in
nested generics as if it was a right-shift. The change is only of
interest to compiler writers and does not affect the code that you
write.

HTH

rossum

--

The ultimate truth is that there is no ultimate truth
Dec 18 '05 #3
ERE
Thanks!

Dan

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ERE <ea*******@ma.ultranet.com> wrote:
Pardon me if this has been asked a million times -- but I thought that
because of generics, the right shift operator was supposed to change with
C#
2.0. I thought it was supposed to change from ">>" to "> >", to
distiguish
it from nested generics.

But I've been using VS2005, and when I put in the new syntax I get an
error
message, whereas the old syntax, as shown in the following code continues
to
work fine. What am I missing?


The right shift operator itself hasn't been changed in terms of what
you write. It's been changed in terms of what one part of the compiler
gives to the other. Instead of the parser recognising one token of
">>" it recognises two tokens, each of which is ">".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: DeepaK K C | last post by:
main() { int a =100; a = a>>32; printf(" %d", a); } it prints "a" as 100 only....but I am expecting a = 0..... can some one tell me the reason?
43
by: Mehta Shailendrakumar | last post by:
Hello, Can anyone suggest me operator to perform arithmetic shift in C? May it be for a perticular compiler. Thank you in advance. Regards, Shailendra
4
by: Kevin | last post by:
I was looking through some source code and noticed the used of the C# << operator. Why is this being used here and under what circumstances is an left-shift operator useful. internal enum...
3
by: Bob | last post by:
What is an equivalent of a Right Shift operator (>>) in visual basic 6.0? I am trying to convert a C++ code into visual basic that looks like the following: While (m < n) { k = (m+n) >> 1 } ...
0
by: ERE | last post by:
Pardon me if this has been asked a million times -- but I thought that the syntax for right shift had changed with C# 2.0. I thought the operator was supposed to change to "> >" (with exactly one...
16
by: Santosh Nayak | last post by:
Hi, Is there any way to catch the losing bit occurring due to Right Shift Operator ? e.g int a = 5 ; a = a >1 ; // // a is now 2 and the least significant bit is lost // // I want this...
4
by: G Iveco | last post by:
I am using this type of code to do right-shifting, B = 3; data1 = (data + (1 << (B-1))) >B; data1 seems incorrect when data = -4-8*i.. which means it rounds -1.5 to -1 instead of -2. On...
11
by: Bob Altman | last post by:
Hi all, I want to write a generic class that does this: Public Class X (Of T) Public Sub Method(param As T) dim x as T = param >3 End Sub End Class
2
by: gaya3 | last post by:
Hi, can anyone explain the unsigned right shift operator with example? And also why there is no unsigned left shift operator? is there any specific reason for that? -Thanks & regards, Hamsa
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.