Qualcomm Interview Question for Developer Program Engineers


Country: United States
Interview Type: In-Person




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

#include <stdio.h>
 
/* function to show bytes in memory, from location start to start+n*/
void show_mem_rep(char *start, int n)
{
    int i;
    for (i = 0; i < n; i++)
         printf(" %.2x", start[i]);
    printf("\n");
}
 
/*Main function to call above function for 0x01234567*/
int main()
{
   int i = 0x01234567;
   show_mem_rep((char *)&i, sizeof(i));
   getchar();
   return 0;

}

little endian machine, gives “67 45 23 01″ as output , big endian machine, gives “01 23 45 67″ as output.

- karthiga.m1988 March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
6
of 6 vote

#include<stdio.h>

int main()
{
  int a = 1;
  char *b;

  b = (char *)&a;
  if (*b)
    printf("Little Endian\n");
  else
    printf("Big Endian\n");
}

- tvbgeek October 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

I would use something much simplier :

const long number=123;
	if(number == htonl(number)){
		printf("This is big endian machine\n");
	} else {
		printf("This is little endian machine\n");
	}

- Youngster March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

why the const ?

- abhi_284 March 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Let's say a=0xAB FE CD FF

1002 | 1003 | 1004 | 1005
----------------------------------------------------------------------------
Big Endian FF CD FE AB
Lil Endian AB FE CD FF
-----------------------------------------------------------------------------
seems to be not correct, for lil endian as LSB has to be at lowest address:
correct representation is the reverse:
1002 | 1003 | 1004 | 1005
Lil Endian FF CD FE AB
Big Endian AB FE CD FF

- Sri March 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

typedef struct union {
	char c;
	int i;
}ENDIAN;

int main()
{
	ENDIAN e;
	e.i = 1;
	if(e.c == 1)
	{
		printf("this is little endian\n");
	}
	else
	{
		printf("this is big endian\n");
	}
        return 0;
}

- gtvforever July 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

void main()
{
int i=1;
char *p=(char *)&i;
if(p[0]==1)
printf("your computer follow LITTLE ENDIAN");
else
printf("your computer follow BIG ENDIAN")
}

- manoj August 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

int main(){
	unsigned int i;
	char *c = (char *)&i;
	if(*c){
      	printf("Littele indian\n");}
	else{
	printf("Big indian\n");}
}

- TusharPatil March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

what does i contain?

- flipper March 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

i=1;

- nishant March 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

@flipper: Please stop surround your ENTIRE comment with squiggly braces. Surround ONLY the source code. If you are not writing source code, do not use squiggly braces. Look at how everyone else is doing it.

- Gayle L McDowell March 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What should be the output if I changed it to

int main(){
unsigned int i=0;


char *c = (char *)&i;
printf("%d",*c);
if(*c){
printf("Little indian\n");
}
else{
printf("Big indian\n");
}
getch();
}

- mkumar9009 April 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@mkimar9009
its going to say Big endian; but obvious it's wrong.
You won't be able to differentiate between Little endian zero & a big endian zero.
Need to seed the test data properly.

can have a check like this

if(i) { // we are using the integer data type here to make sure that the test data is valid.
	// Do the test of endiness here.
	}

- Yuri April 11, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) {
    int foo = 1 + 2*256 + 3*(256*256) + 4*(256*256*256);
    int i;
    char *p = &foo;
    for (i = 0; i < 4; ++i) {
        printf("%d: %c\n", i, '0' + p[i]);
    }
    return 0;
}

- showell30@yahoo.com March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What do you need stdlib.h for ?

- abhi_284 March 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You don't need it.

- showell30@yahoo.com March 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a = 0x1;
    bool LittleEndian = ((char*)&a)[0] & 1;

- iimanii March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Check on simple link of wiki

- vikas pushkar March 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What is little endian and big endian?

- Anand March 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Lil endia-> MSB to LSB are kept at high to lower memory address
big endian-> MSB to LSB are kept at lower to higher address location

Let's say a=0xAB FE CD FF

1002 | 1003 | 1004 | 1005
----------------------------------------------------------------------------
Big Endian FF CD FE AB
Lil Endian AB FE CD FF
-----------------------------------------------------------------------------

Endian means the byte ordering;


$ echo -n I | od -to2 | head -n1 | cut -f2 -d" " | cut -c6 is the command to knw endianness of system

If it gives 0 then big if 1 then lil

- vikaskupushkar March 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you please explain what this chain of commands does ?
echo -n I | od -to2

Also I tried this on my PC (intel 64) which I believe is little endian and got a 0 as the outcome.

- abhi_284 March 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

using java.nio library you can find the native byte order of the hardware on which JVM is running.

- AlgoAlgae June 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef union u
{
char c[2];
short b;
}u_t;

int main()
{
u_t u1;
u1.b=1;
if (c[0]==1)
{
printf("little endian");
}
else
{
printf("big endian");
}
}

- prasad June 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>

int main(int argc,char **argv){
int i = 1;
char *ptr = (char*)&i;
if(*ptr == 1){
printf("Little Endian");
}else{
printf("Big Endian");
}

- geeksystems February 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int num = 1;
if(*(char *)&num == 1)
{
printf("\nLittle-Endian\n");
}
else
{
printf("Big-Endian\n");
}

- bks February 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

take one variable with value 1.. shift it by 2 if it comes greater than 1 that lil endian if comes 0 then big.. if it comes 1 than check your shifting is wrong ;)

- vikaskupushkar March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I tried the same comman with "echo -n I" and "echo -n P". It gives 1 in one case and 0 in another. Any specific reason to echo "I"??

- PTyagi May 23, 2013 | Flag


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