Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do two left-angle brackets "<<" mean in C#?

Basically the questions in the title. I'm looking at the MVC 2 source code:

[Flags] public enum HttpVerbs {     Get = 1 << 0,     Post = 1 << 1,     Put = 1 << 2,     Delete = 1 << 3,     Head = 1 << 4 } 

and I'm just curious as to what the double left angle brackers << does.

like image 717
lancscoder Avatar asked Mar 22 '10 15:03

lancscoder


People also ask

What does << mean in C sharp?

Definition. The left-shift operator (<<) shifts its first operand left by the number of bits specified by its second operand. The type of the second operand must be an int. <<

What is angle bracket in C?

angular brackets are used for global use of the header files which are predefined and we include in our program. if we use user defined header file we need put " " instead of < >

What do the angle brackets mean in C ++?

Angle brackets in programming languages In C++ chevrons (actually less-than and greater-than) are used to surround arguments to templates. In the Z formal specification language chevrons define a sequence.

What is>> in cmd?

61. >> can be used to pipe output into a text file and will append to any existing text in that file. 'any command' >> textfile.txt. appends the output of 'any command' to the text file.


1 Answers

When you write

1 << n 

You shift the bit combination 000000001 for n times left and thus put n into the exponent of 2:

2^n 

So

1 << 10 

Really is

1024 

For a list of say 5 items your for will cycle 32 times.

like image 146
pid Avatar answered Oct 01 '22 03:10

pid