- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How to multiply a given number by 2 using Bitwise Operators in C#?

A number can be multiplied by 2 using bitwise operators. This is done by using the left shift operator and shifting the bits left by 1. This results in double the previous number.

A program that demonstrates multiplication of a number by 2 using bitwise operators is given as follows.

## Example

using System; namespace BitwiseDemo { class Example { static void Main(string[] args) { int num = 25, result; result = num << 1; Console.WriteLine("The original number is: {0}", num); Console.WriteLine("The number multiplied by two is: {0}", result); } } }

## Output

The output of the above program is as follows.

The original number is: 25 The number multiplied by two is: 50

Now let us understand the above program.

First, the number is defined. Then, the left shift operator is used and the bits in num are shifted left by 1. This results in double the previous number which is stored in result. Then, the values of num and result are displayed. The code snippet for this is given as follows −

int num = 25, result; result = num << 1; Console.WriteLine("The original number is: {0}", num); Console.WriteLine("The number multiplied by two is: {0}", result);

- Related Questions & Answers
- Multiply a number by 15 without using * and / operators in C++
- Multiply any Number with using Bitwise Operator in C++
- Java Bitwise Operators
- Perl Bitwise Operators
- Python Bitwise Operators
- Bitwise Operators in C
- Bitwise Operators in C++
- C program for Addition and Multiplication by 2 using Bitwise Operations.
- C++ Program to Perform Addition Operation Using Bitwise Operators
- Bitwise operators in Dart Programming
- How to multiply all values in a list by a number in R?
- What are JavaScript Bitwise Operators?
- Bitwise right shift operators in C#
- What are bitwise operators in C#?
- Explain about bitwise operators in JavaScript?

Advertisements