Qualcomm Interview Question for Software Engineer / Developers






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

unsigned int
reverse_8bit(register unsigned int x)
{
x = (((x & 0xaa) >> 1) | ((x & 0x55) << 1));
x = (((x & 0xccc) >> 2) | ((x & 0x333) << 2));
x = (((x & 0xf0) >> 4) | ((x & 0x0f) << 4));

return x;
}

}

- Anonymous July 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

unsigned int
reverse(register unsigned int x)
{
x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
return((x >> 16) | (x << 16));

}

- Anonymous March 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

unsigned char reverse(unsigned char x)
{
 unsigned char h = 0;
 int i = 0;

 for(h = i = 0; i < sizeof(x); i++) {
  h = (h << 1) | (x & 1); 
  x >>= 1;
 }

 return h;
}

- Another Coder March 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is for 32 bit

- Anonymous March 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Reversing by using a lookup table of 256 values would be the fastest.

- Bandicoot April 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
char reverse(char x){
int h= 0,temp=0;
int len=8;
for(int i = 0;i<len;i++)
{
temp = 0;
temp |= x&(0x01<<i);
temp = temp>>i;
h|=temp<<(len-1-i);
}
return h;
}
int main()
{
char ch = 0x12;
printf("actual =%x, reversed =%x",ch,reverse(ch));
return 0;
}

- Cheers April 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void reverse_bit(unsigned char num)
{
unsigned int i,rev_bit=0;
printf("Enter a Number \n");
scanf("%x",&num);
for(i=0;i<(sizeof(num)*8);i++)
{
rev_bit|=((num ^ (0x1<<i)) &(0x1<<i));
}
printf("Total=0x%x\n",rev_bit);
}

- Anonymous July 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void reverse_bit(unsigned char num)
{
unsigned int i,rev_bit=0;
printf("Enter a Number \n");
scanf("%x",&num);
for(i=0;i<(sizeof(num)*8);i++)
{
rev_bit|=((num ^ (0x1<<i)) &(0x1<<i));
}
printf("Value after Bit manipulation=0x%x\n",rev_bit);
}

- Abhijeet Dandade July 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int main(){
unsigned int i = 128;
int j = 0;
int r = 0;
for(j = 0; j < 8 ; j++){
r = (r << 1) | ((i >> j) & 1);
}
printf(" %d\n ", r);

return 0;
}

- Just another coder May 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
uint8_t n = 0x11;
uint8_t tempn=0x11;
int i=0;
for(i=0;i<8;i++)
{
if(tempn & 0x80)
{
n = n | (1 << i);
}
else
{
n = n & ~(1 << i) ;
}

tempn = tempn << 1;
}
printf("%x ",n);
}

- Anonymous May 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Only need to do the xor with 0xFFFF.

- Anonymous September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

uint8 m;
m ^= 0xFF;

- Anonymous September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char ReverseUint8 ( char x)
{
char y = 0;
int i;
unsigned char var = 0x01;
unsigned char var_f = 0x80;
for ( i = 0 ; i < 8 ; i++)
{
if ( x & var )
{
y |= var_f;
}

var = var<<1;
var_f = var_f>>1;

// printf("\n x = %d , y = %d ",x, y);

}

return y;
}

- Anonymous October 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey54315" class="run-this">/* I tried this. It works */
char ReverseUint8 ( char x)
{
char y = 0;
int i;
unsigned char var = 0x01;
unsigned char var_f = 0x80;
for ( i = 0 ; i < 8 ; i++)
{
if ( x & var )
{
y |= var_f;
}

var = var<<1;
var_f = var_f>>1;

// printf("\n x = %d , y = %d ",x, y);

}

return y;
}</pre><pre title="CodeMonkey54315" input="yes">
</pre>

- Anonymous October 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char str[10];
cout<<"\nEnter A String\n";
cin>>str;
char *ptr;
int len=0;
for(ptr=str;*ptr!='\0';ptr++,len++);
cout<<"String Length Is: "<<len<<"\n";
cout<<"\Reverse String: ";
for(--ptr;ptr>=str;ptr--)
cout<<*ptr;
getch();
}

- skkp October 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static int bitr(int j) {
int numBits = (int) (Math.log(j) / Math.log(2));
int ans = 0;
for (int i = 0; i < numBits; i++) {
ans = (ans << 1) + (j & 1);
j = j >> 1;
}
return ans;
}

- jerry February 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char a;
a = ((a & 0xF0) >> 4) | ((a & 0x0F) << 4)

that will do it.

- n00bCod3R March 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Reverse the bits in a byte with 3 operations (64-bit multiply and modulus division):

unsigned char b; // reverse this (8-bit) byte

b = (b * 0x0202020202ULL & 0x010884422010ULL) % 1023;
The multiply operation creates five separate copies of the 8-bit byte pattern to fan-out into a 64-bit value. The AND operation selects the bits that are in the correct (reversed) positions, relative to each 10-bit groups of bits. The multiply and the AND operations copy the bits from the original byte so they each appear in only one of the 10-bit sets. The reversed positions of the bits from the original byte coincide with their relative positions within any 10-bit set. The last step, which involves modulus division by 2^10 - 1, has the effect of merging together each set of 10 bits (from positions 0-9, 10-19, 20-29, ...) in the 64-bit value. They do not overlap, so the addition steps underlying the modulus division behave like or operations.

- Rohan May 09, 2012 | Flag Reply


Add a Comment
Name:

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

Books

is a comprehensive book on 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