Q:

Write a program to check an integer is a power of 2?

0

Write a program to check an integer is a power of 2?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

Here, I am writing a small algorithm to check the power of 2. If a number is a power of 2, function return 1.

int CheckPowerOftwo (unsigned int x)
{
    return ((x != 0) && !(x & (x - 1)));
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Embedded C interview questions and answers (2022)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is the output of the below code?... >>
<< Where can the function pointers be used?...