using System;
class Example {
public static void Main() {
int n;
n = 10;
Console.WriteLine("Value of n: " + n);
Console.WriteLine("multiply by 2");
n = n << 1;
Console.WriteLine("Value of n after n = n * 2: " + n);
Console.WriteLine("multiply by 4");
n = n << 2;
Console.WriteLine("Value of n after n = n * 4: " + n);
Console.WriteLine("divide by 2");
n = n >> 1;
Console.WriteLine("Value of n after n = n / 2: " + n);
Console.WriteLine("divide by 4");
n = n >> 2;
Console.WriteLine("Value of n after n = n / 4: " + n);
Console.WriteLine();
Console.WriteLine("reset n");
n = 10;
Console.WriteLine("Value of n: " + n);
Console.WriteLine("multiply by 2, 30 times");
n = n << 30; // data is lost
Console.WriteLine("Value of n after left-shifting 30 places: " + n);
}
}
|