4
Answers

Shift

Maha

Maha

11y
947
1
You can see from this example right sift operator keep the original size of the bits always the same but left shift operator adding bits to the original size of the bits thus increasing the size of total bits. Please explain the differences. Problem is highlighted.

using System;

class Program
{
static void Main()
{
int value1 = 10;//1010 
int i = 1;

int shift = value1 >> i;
Console.WriteLine("{0}", shift);//0101=5

shift = value1 << i;
Console.WriteLine("\n{0}", shift);//10100=20

shift = value1 << 2;
Console.WriteLine("\n{0}", shift);//101000=40

shift = value1 >> 2;
Console.WriteLine("\n{0}", shift);//0010=2

Console.ReadKey();
}
}

Answers (4)