C# Program to Multiply given Number by 4 using Bitwise Operators

«
»

This is a C# Program to multiply given number by 4 using bitwise operators.

Problem Description

This C# Program Multiplies given Number by 4 using Bitwise Operators.

Problem Solution

Here The bitwise operators are or, and, xor, not, left shift, right shift. Program uses left shift operator for this.

advertisement
Program/Source Code

Here is source code of the C# Program to Multiply given Number by 4 using Bitwise Operators. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Multiply given Number by 4 using Bitwise Operators
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            int number, tempnum;
            Console.WriteLine("Enter an integer :");
            number = int.Parse(Console.ReadLine());
            tempnum = number;
            number = number << 2;
            Console.WriteLine("{0},{1}", tempnum, number);
            Console.ReadLine();
        }
    }
}
Program Explanation

In this C# program, we are reading an integer value using ‘number’ variable. Binary Left Shift Operator is used to move the value of left operands by the number of bits specified by the value of right operand. Print the multiplied value of the given number.

Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
advertisement
Runtime Test Cases
 
Enter an integer :
120
120,480

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

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
advertisement
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 & technical discussions at Telegram SanfoundryClasses.