Hello ppl,
I have recently started C# and while going through initial pages of bitwise operators 1 doubt came into mind.
v know dat int is of 32 bits in C#. Suppose i take a number and assign some value to it and then after left shifting it by 32,the number doesn't get changed. If i do left shift 33 times the number gets multiplied by 2. However Left shifting by 31 and then left shifting it by 1 after that will make the number 0.
What is actually happening....plz help
to my surprise same 16 left shifting in C(as int is 16 bits in C) will make the number 0 and by left shifting 17 will keep the number to 0.
My Code Snippet for the same is:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int num=7;
num = num << 32;
Console.WriteLine("Left shift by 32->"+num);
num = 7;
num = num << 33;
Console.WriteLine("Left shift by 33->"+num);
num = 7;
num = num << 31;
num = num << 1;
Console.WriteLine("Left shift 31 first den left shift once again->" + num);
Console.ReadKey();
}
}
}