We are a Number n and our task is multiply the number with 4 using bit-wise Operator.
Input : 4 Output :16 Input :5 Output :20
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
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.
- Multiply a number with 10 without using multiplication operator
- Russian Peasant (Multiply two numbers using bitwise operators)
- Find the remainder when N is divided by 4 using Bitwise AND operator
- Multiply a number by 15 without using * and / operators
- Total pairs in an array such that the bitwise AND, bitwise OR and bitwise XOR of LSB is 1
- Leftover element after performing alternate Bitwise OR and Bitwise XOR operations on adjacent pairs
- Bitwise OR( | ) of all even number from 1 to N
- Print bitwise AND set of a number N
- Number of pairs with Bitwise OR as Odd number
- Check if a Number is Odd or Even using Bitwise Operators
- Count pairs with Bitwise-AND as even number
- Number of ways to swap two bit of s1 so that bitwise OR of s1 and s2 changes
- Count pairs with Bitwise OR as Even number
- Count pairs with Bitwise AND as ODD number
- Count pairs with Bitwise XOR as ODD number
- Count pairs with Bitwise XOR as EVEN number
- Find subsequences with maximum Bitwise AND and Bitwise OR
- Check if a number is divisible by 17 using bitwise operators
- Check if a number is divisible by 8 using bitwise operators
- Check if a number is multiple of 9 using bitwise operators
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.