i couldn't understand this code in c#
int i=4
int[] s =new int [1<<i];
Console.WriteLine(s.length);
the ouput is 16 i don't know why the output like that?
bit shift operator
From documentation
If first operand is an int or uint (32-bit quantity), the shift count is given by the low-order five bits of second operand.
If first operand is a long or ulong (64-bit quantity), the shift count is given by the low-order six bits of second operand.
Note that i<<1 and i<<33 give the same result, because 1 and 33 have the same low-order five bits.
This will be the same as 2^( the actual value of the lower 5 bits ).
So in your case it would be 2^4=16.
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