How do you find out if a number is a power of 2? And how do you know if it is an odd number? Write code in the language of your choice

AnswerBot
1y

Check if a number is a power of 2 and odd.

  • To check if a number is a power of 2, use bitwise AND operator with the number and its predecessor. If the result is 0, it is a power of 2.

  • To check if a numbe...read more

Anonymous
2y

Keep dividing the number by two, i.e, do n = n/2 iteratively until n becomes 1. In any iteration, if n%2 becomes non-zero and n is not 1 then n is not a power of 2. If n becomes 1 then it is a power o...read more

Prajwal Jadhav
5y

N=[(log(x))÷(1-log(5))] 

If value of N is in integer then x is in power of 2 else it's not.

If X%2==1 then x is odd

Add answer anonymously...
Google Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter