189k views
2 votes
Left-shifting an unsigned int by 1 bit is equivalent to multiplying the value by 2. write function power2 that takes two integer arguments number and pow and calculates number * 2

a) The function multiplies number by 2 raised to the power of pow.
b) The function raises number to the power of 2 and then multiplies by pow.
c) The function shifts number left by pow bits.
d) The function calculates 2 raised to the power of number multiplied by pow.

User Idbrii
by
8.2k points

1 Answer

3 votes

Final answer:

Left-shifting an unsigned int by 1 bit is equivalent to multiplying the value by 2. Option c) The function shifts number left by pow bits is the correct option to calculate number * 2 raised to the power of pow.

Step-by-step explanation:

Left-shifting an unsigned int by 1 bit is equivalent to multiplying the value by 2. In other words, shifting the bits of an unsigned int to the left by 1 position is equivalent to multiplying the value by 2.

In the given function, power2, the correct option to calculate number * 2 raised to the power of pow is option c) The function shifts number left by pow bits.

For example, if we have number = 5 and pow = 3, the function would shift number to the left by 3 bits, resulting in 40.

User Ritz
by
8.3k points