In some languages, a double set of angle brackets may be used in place of quotation marks to contain quotes. In English, they may be used informally to insert asides, indicate speech in a foreign language, or to mention a website, but all of these uses are rare even in informal writing.
An angle bracket is the combination of a bra and ket (bra+ket = bracket) which represents the inner product of two functions or vectors (or 1-forms), in a function space, or. in a vector space.
The angle bracket (< or >), which is also called an “inequality sign” for its use in mathematics, is a kind of sideways caret that can be used to include tags or pieces of code. This ASCII set of characters is common in web design and other types of coding projects.
>> 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.
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.
It is called left-shift
operator. Take a look at the documentation
The left-shift operator causes the bit pattern in the first operand to be shifted to the left by the number of bits specified by the second operand. Bits vacated by the shift operation are zero-filled. This is a logical shift instead of a shift-and-rotate operation.
Simple example that demonstrates the left-shift
operator:
for (int i = 0; i < 10; i++)
{
var shiftedValue = 1 << i;
Console.WriteLine(" 1 << {0} = {1} \t Binary: {2}",i,shiftedValue,Convert.ToString(shiftedValue,2).PadLeft(10,'0'));
}
//Output:
// 1 << 0 = 1 Binary: 0000000001
// 1 << 1 = 2 Binary: 0000000010
// 1 << 2 = 4 Binary: 0000000100
// 1 << 3 = 8 Binary: 0000001000
// 1 << 4 = 16 Binary: 0000010000
// 1 << 5 = 32 Binary: 0000100000
// 1 << 6 = 64 Binary: 0001000000
// 1 << 7 = 128 Binary: 0010000000
// 1 << 8 = 256 Binary: 0100000000
// 1 << 9 = 512 Binary: 1000000000
Moving one bit to left is equivelant to multiple by two.In fact,moving bits are faster than standart multiplication.Let's take a look at an example that demonstrates this fact:
Let's say we have two methods:
static void ShiftBits(long number,int count)
{
long value = number;
for (int i = 0; i < count; i+=128)
{
for (int j = 1; j < 65; j++)
{
value = value << j;
}
for (int j = 1; j < 65; j++)
{
value = value >> j;
}
}
}
static void MultipleAndDivide(long number, int count)
{
long value = number;
for (int i = 0; i < count; i += 128)
{
for (int j = 1; j < 65; j++)
{
value = value * (2 * j);
}
for (int j = 1; j < 65; j++)
{
value = value / (2 * j);
}
}
}
And we want to test them like this:
ShiftBits(1, 10000000);
ShiftBits(1, 100000000);
ShiftBits(1, 1000000000);
...
MultipleAndDivide(1, 10000000);
MultipleAndDivide(1, 100000000);
MultipleAndDivide(1, 1000000000);
...
Here is the results:
Bit manipulation 10.000.000 times: 58 milliseconds
Bit manipulation 100.000.000 times: 375 milliseconds
Bit manipulation 1.000.000.000 times: 4073 milliseconds
Multiplication and Division 10.000.000 times: 81 milliseconds
Multiplication and Division 100.000.000 times: 824 milliseconds
Multiplication and Division 1.000.000.000 times: 8224 milliseconds
That would be the bitwise left shift operator.
For each shift left, the value is effectively multiplied by 2. So, for example, writing value << 3
will multiply the value by 8.
What it really does internally is move all of the actual bits of the value left one place. So if you have the value 12 (decimal), in binary that is 00001100
; shifting it left one place will turn that into 00011000
, or 24.
It is Bitwise shift left it works by shifting digits of binary equivalent of number by the given (right hand side) numbers.
so:
temp = 14 << 2
binary equivalent of 14 is 00001110
shifting it 2 times means pushing zero from right hand side and shifting each digit to left side which make it 00111000
equals to 56.
In your example:
i < (1 << list.Count)
and so on. In general it is equal 2 ^ list.Count
(2 raised to the power of list.Count)
That's the left bitshift operator. It shifts the bit pattern of the left operand to the left by the number of binary digits specified in the right operand.
Get = 1 << 0, // 1
Post = 1 << 1, // 2
Put = 1 << 2, // 4
Delete = 1 << 3, // 8
Head = 1 << 4 // 16
This is semantically equivalent to lOperand * Math.Pow(2, rOperand)
The purpose of the loop is most likely to generate or operate on all subsets of the set of items in the list. And the loop body most likely also has a good bit (har har) of bitwise operations, namely both another left-shift and bitwise-and. (So rewriting it to use Pow would be mighty stupid, I can hardly believe there were so many people that actually suggested that.)
Thats bit shifting. Its basically just moving the bits to the left by adding 0's to the right side.
public enum HttpVerbs {
Get = 1 << 0, // 00000001 -> 00000001 = 1
Post = 1 << 1, // 00000001 -> 00000010 = 2
Put = 1 << 2, // 00000001 -> 00000100 = 4
Delete = 1 << 3, // 00000001 -> 00001000 = 8
Head = 1 << 4 // 00000001 -> 00010000 = 16
}
More info at http://www.blackwasp.co.uk/CSharpShiftOperators.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With