Qualcomm Interview Question Software Engineer in Tests




Comment hidden because of low score. Click to expand.
1
of 1 vote

for unsigned integer nummbers:
bool isPow2(int n)
{
return !(n & (n-1)) && n;
}

- strezh on October 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

if number of bits set is 1 then it is a power of two

- chennavarri on October 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for unsigned integer numbers:
bool isPow2(int n)
{
return !(n & (n-1)) && n;
}

- strezh on October 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

return num&(num-1)==0

- Xtra on October 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can you explain it?

- Anonymous on November 24, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

let us take num=8 (2 pow 3) and n-1 means 7
n =1000
n-1=0111 perform & operation
----------------
0000
------------- so 8 is power of 2

- vamsha on July 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

return ((pow(2,log2(n))-pow(2,floor(log2(n))))==0)

- chennavarri on October 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isPow2(unsigned int n){
if(n==0)
return false;
return (n&(n-1))==0;
}

- phe on January 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If(x && !(x & (x-1))==0)

- Sandy880 on January 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Jay: Thats interesting point. I was wondering if Negative numbers can be powers of positive number!

- suman on April 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool ispowerof2(int x)
{
int p = x & -x;
return p == x || p == -x;
}

- Anurag Singh on May 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

powers of a +ve number 2 will always be +ve

- raped on July 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
bool val ( int n);
int main ()
{
if(val(1024) == true)
cout << "yes";
else
cout <<"no";

}

bool val(int n)
{

if( n <= 1)
return false;

while(n>1)
{
if(n%2 != 0)
return false;
else
n = n / 2;
}

return true;
}

- Shahid Siddique on June 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static void Main(string[] args)
{
int number = enter any no;
int quotient = 0;
int mod = 0;
while(number >= 2)
{
mod = number % 2;
quotient = number / 2;

if (mod == 0 && number >= 2)
{
number = quotient; ;
continue;
}
else break;
}
if (mod == 0)
{
Console.WriteLine("number power of 2");
}
else
{
Console.WriteLine("number not power of 2");
}
Console.ReadLine();
}

- AN on June 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

What about negative number? such as -4. -4 is power of 2 too.

- Jay on January 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

For negative numbers add this line:

bool isPow2(int n){
n=n<0?-n:n;
return !(n & (n-1));
}

- Jerome on February 01, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How? Look at the exponential graph, it never goes below 0 past the x axis.

Also, 2^x = -4, give me x. You can't. The power of any positive integer, such as 2, is always positive. Remember that a number raised to a negative number is just a positive inverse. Therefore, this case is invalid.

- alchu8 on May 24, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book walking you through getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More