Nios/pow2

From ASMBits

Write a function that will return whether its parameter is a power of 2. The parameter is an unsigned integer and will not be 0.

int pow2(unsigned int num);

Expected solution length: Around 4 lines.

Sample Input

pow2(4)

Sample Output

r2=1

It is possible to do this without a loop. Consider the binary representations of (2n) and (2n-1).

Write your solution here

Upload a source file...