# Multiply any Number with 4 using Bitwise Operator

We are a Number n and our task is multiply the number with 4 using bit-wise Operator.

Examples:

```Input : 4
Output :16

Input :5
Output :20
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Explanation Case 1:- n=4 the binary of 4 is 100 and now shift two bit right then 10000 now the number is 16 that is multiply 4*4=16 ans.
Approach :- (n<<2) shift two bit right

## C++

 `// C++ program to multiply a number with  ` `// 4 using Bitwise Operator ` `#include ` `using` `namespace` `std; ` ` `  `// function the return multiply a number ` `//  with 4 using bitwise operator ` `int` `multiplyWith4(``int` `n) ` `{ ` `    ``// returning a number with multipy  ` `    ``// with 4 using2 bit shifring right ` `    ``return` `(n << 2); ` `} ` ` `  `// derive function ` `int` `main() ` `{ ` `    ``int` `n = 4; ` `    ``cout << multiplyWith4(n) << endl; ` `    ``return` `0; ` `} `

## Java

 `// Java program to multiply a number ` `// with 4 using Bitwise Operator ` ` `  `class` `GFG { ` `     `  `// function the return ` `// multiply a number ` `// with 4 using bitwise  ` `// operator ` `static` `int` `multiplyWith4(``int` `n) ` `{ ` `     `  `    ``// returning a number ` `    ``// with multipy with  ` `    ``// 4 using 2 bit shifting ` `    ``// right ` `    ``return` `(n << ``2``); ` `} ` ` `  `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` `    ``int` `n = ``4``; ` `    ``System.out.print(multiplyWith4(n)); ` `} ` `} ` ` `  `// This code is contributed by Smitha. `

## Python 3

 `# Python 3 program to multiply ` `# a number with 4 using Bitwise ` `# Operator ` ` `  `# function the return multiply ` `# a number with 4 using bitwise ` `# operator ` `def` `multiplyWith4(n): ` ` `  `    ``# returning a number with ` `    ``# multipy with 4 using2 ` `    ``# bit shifring right ` `    ``return` `(n << ``2``) ` ` `  `# derive function ` `n ``=` `4` `print``(multiplyWith4(n)) ` ` `  `# This code is contributed ` `# by Smitha `

## C#

 `// C# program to multiply a number ` `// with 4 using Bitwise Operator ` `using` `System; ` ` `  `class` `GFG { ` `     `  `// function the return ` `// multiply a number ` `// with 4 using bitwise  ` `// operator ` `static` `int` `multiplyWith4(``int` `n) ` `{ ` `     `  `    ``// returning a number ` `    ``// with multipy with  ` `    ``// 4 using 2 bit shifting ` `    ``// right ` `    ``return` `(n << 2); ` `} ` ` `  `// Driver Code ` `public` `static` `void` `Main(String[] args) ` `{ ` `    ``int` `n = 4; ` `    ``Console.Write(multiplyWith4(n)); ` `} ` `} ` ` `  `// This code is contributed by Smitha. `

## PHP

 ` `

Output :-

```16
```

Generalization : In general, we can multiply with a power of 2 using bitwise operators. For example, suppose we wish to multiply with 16 (which is 24), we can do it by left shifting by 4.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up It doesnt make sense to hire smart people and tell them what to do we hire smart people so they can tell us what to doo

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.