This article shows the use of the left Shift operator in a program in C#. You need to have the knowledge of the following before you go ahead.
The Left Shift Operator in C# allows the creators to shift the bits to their left for the adjustments. The position it needs to shift is determined by the additive expression.
Question:
Write a C# program to Illustrate the Left Shift Operator Operation
C# Program for Left Shift Operator Operation
Source code.
using System;
class LeftShiftOperation
{
public static void Main()
{
int a = 1024 * 1024 * 1024;
uint p = 1024 * 1024 * 1024;
int b = -42;
Console.WriteLine("Example of Left Shift Operation:");
Console.WriteLine("{0},{1},{2}", a, a *2, a << 1);
Console.WriteLine("{0},{1},{2}", p, p *2, p << 1);
Console.WriteLine("{0},{1},{2}", a, a *4, a << 2);
Console.WriteLine("{0},{1},{2}", p, p *4, p << 2);
Console.WriteLine("{0},{1},{2}", b, b *1024 * 1024 *64, a << 26);
}
}
Output:
