C# Program to Demonstrate LeftShift Operations


This is a C# Program to illustrate leftshift operations.

Problem Description

This C# Program Illustrates LeftShift Operations.

Problem Solution

The shift operators allow programmers to adjust an integer by shifting all of its bits to the left or the right.

Program/Source Code

Here is source code of the C# Program to Illustrate LeftShift Operations. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

 * C# Program to Illustrate LeftShift Operations
using System;
class sample
    public static void Main()
        int x = 1024 * 1024 * 1024;
        uint p = 1024 * 1024 * 1024;
        int y = -42;
        Console.WriteLine("LEFT SHIFT OPERATIONS :");
        Console.WriteLine("{0},{1},{2}", x, x * 2, x << 1);
        Console.WriteLine("{0},{1},{2}", p, p * 2, p << 1);
        Console.WriteLine("{0},{1},{2}", x, x * 4, x << 2);
        Console.WriteLine("{0},{1},{2}", p, p * 4, p << 2);
        Console.WriteLine("{0},{1},{2}", y, y * 1024 * 1024 * 64, x << 26);
Program Explanation

In this C# program, illustrate leftshift operations. Using ‘x’ integer and ‘p’ unsigned integer variable multiply 1024 value as thrice. Assign -42 values to ‘y’ integer variable.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

The shift operators allow programmers to adjust an integer by shifting all of its bits to the left or the right. Print the value using leftshift operations.

Runtime Test Cases

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

Check this: C# Books | MCA MCQs
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.