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 position. This operation results in double the previous number because each left shift by one position is equivalent to multiplying by 2.

Syntax

Following is the syntax for using the left shift operator to multiply by 2 −

result = number << 1;

Where number is the value to be multiplied, and 1 is the number of positions to shift left.

How It Works

The left shift operator moves all bits in the binary representation of a number to the left by the specified number of positions. When we shift left by 1, each bit moves one position left, effectively doubling the number's value.

Left Shift Operation (25 << 1) 25 in binary: 0 0 0 1 1 0 0 1 50 in binary: 0 0 1 1 0 0 1 0 = 25 = 50 All bits shifted left by 1 position, 0 added at right

Example

A program that demonstrates multiplication of a number by 2 using bitwise operators −

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);
        }
    }
}

The output of the above code is −

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

Using Left Shift with Different Numbers

The left shift operation works with any integer value −

using System;

class Program {
    static void Main() {
        int[] numbers = {5, 12, 100, 7};
        
        Console.WriteLine("Original\tShifted Left\tResult");
        Console.WriteLine("--------\t------------\t------");
        
        foreach(int num in numbers) {
            int doubled = num << 1;
            Console.WriteLine("{0}\t\t{0} << 1\t\t{1}", num, doubled);
        }
    }
}

The output of the above code is −

Original	Shifted Left	Result
--------	------------	------
5		5 << 1		10
12		12 << 1		24
100		100 << 1	200
7		7 << 1		14

Comparison with Regular Multiplication

Method Syntax Performance Readability
Left Shift num << 1 Faster (single CPU instruction) Less obvious for beginners
Regular Multiplication num * 2 Slightly slower More readable and clear

Conclusion

The left shift operator (<<) provides an efficient way to multiply a number by 2 by shifting all bits one position to the left. While this bitwise operation is faster than regular multiplication, modern compilers often optimize num * 2 to use bit shifting automatically, making readability the primary consideration when choosing between methods.

Updated on: 2026-03-17T07:04:35+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements