1285. Multiply a Number by 2 Using Left Shift

EasyBit ManipulationBit ManipulationShiftArithmetic

Given an integer n and a non-negative exponent k, compute n multiplied by 2^k using a left shift instead of multiplication. The classic 'multiply by 2' is the special case k = 1.

Input: A JSON object {"n": <integer>, "k": <exponent>} with 0 <= k <= 20.

Output: Return n * 2^k as an integer.

Examples

Example 1
Input: {"n":5,"k":1}
Output: 10
Explanation: 5 << 1 = 10 = 5 * 2.
Example 2
Input: {"n":3,"k":4}
Output: 48
Explanation: 3 << 4 = 48 = 3 * 16.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →