## Adobe Interview Question for Member Technical Staffs

Country: India
Interview Type: In-Person

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

This was my answer. He was satisfied with this.

``````int convert(int x)
{
int c = n;
c = c << 8 | n;
c = c << 16 | c;
return c;
}``````

Comment hidden because of low score. Click to expand.
0

that is how << and | works.

Comment hidden because of low score. Click to expand.
0

wht abt this code??

int p;
printf("enter any hex number");
scanf("%x",&p);
int q;
int r;
q=p;
r=q<<8;
p=p|r;
r=q<<16;
p=p|r;
r=q<<24;
p=p|r;

printf("0X %x",p);

Comment hidden because of low score. Click to expand.
-2

I don't understand why you get 8 votes, I would give you -1 if I have time.

int converint(int a)
{
return a<<24|a<<16|a<<8|a;
}

Comment hidden because of low score. Click to expand.
0

He first computes 0x2525 and then shifts that and ORs that. Yes, there is a typo of using n instead of x, but we can give him that.

But your solution is more readable, and quite possibly more efficient (inspite of the extra bit shift and bitwise or as compared to the +8 solution), as the compiler can work with registers only and not deal with any locals.

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

Corrected version

``````int convert(int x)
{
int c = x;
c = c << 8 | c;
c = c << 16 | c;
return c;
}``````

Comment hidden because of low score. Click to expand.
0

Could you explain how it works??

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

Correct Me if I m Wrong :

int convert(int x)
{
int c = x;
c = c << 8 | c;
c = c << 8 | c; // Rather Than c = c << 16 | c;
return c;
}

Comment hidden because of low score. Click to expand.
0

1). c = 0x25
after right shift 8 bit
c = 0x2500
now OR with x
c = 0x2525
similarly for next shift

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

int convert(int n)
{
retrun (0x01010101 * n);
}

Comment hidden because of low score. Click to expand.
0

This is fine but can some body write a good tutorial on this concept ? I want to understand this concept thoroughly..

Plz if some one can or give pointer from where I can study this.

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

Int32 X = 0x25;
Int32 Y = 0;
for (int i = 0; i < 4; i++)
{
Y = ((Y << 8) | X);
}

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

Int32 X = 0x25;
Int32 Y = 0;
for (int i = 0; i < 4; i++)
{
Y = ((Y << 8) | X);
}
return Y;

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

res |= (num << 16)|(num << 8);

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

res |= (num << 16)|(num << 8);

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

Assuming 32-bit

int b =0x25; // any hex number
b = b+((b & 0xffff) << 8);
b = b+((b & 0xffff) << 16);

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

after using left shift operator by 8(0x25<<8),only last 8 bit information will still there(0x00) not any 16 bit information like(0x2500).

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

@Neha: You are wrong. Integer is of 4 bytes. So it can hold upto 32 bit info.

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

``````#include<stdio.h>
void main()
{
int num = 0x25,i;
for(i=0;i<4;i++)
{
num = num << 8 | num;
}
printf("%X",num);
}``````

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

convert x int to decima it will give 37 multiply it with 623191333 it will give a number whose hexadecimal form will be y.

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

``````main()
{

int i;
int count;
long y;
while(1)
{
y=0;
count=0;
printf("Input and number :");
scanf("%u", &i);
printf("You entered %d (0x%x)\n", i,i);

if(i>255)
{
printf("enter number less that 256\n");
continue;
}

while(count++!=sizeof(y))
{
printf(".");
y = (y<<8)|i;
}

printf("\nOutput %ld (0x%lx)\n", y,y);
}``````

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

``````main()
{

int i;
int count;
long y;
while(1)
{
y=0;
count=0;
printf("Input and number :");
scanf("%u", &i);
printf("You entered %d (0x%x)\n", i,i);

if(i>255)
{
printf("enter number less that 256\n");
continue;
}

while(count++!=sizeof(y))
{
printf(".");
y = (y<<8)|i;
}

printf("\nOutput %ld (0x%lx)\n", y,y);
}``````

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

#include<stdio.h>
void main()
{
int num = 0x25,i;
char *ch;
ch = (char *)&num;
printf("%X\n",num);
for(i=0;i<4;i++)
{
*ch=num;
printf("%X\n",*ch);
ch=ch+1;

}
printf("%X\n",num);

}

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

#include <stdio.h>

int main() {
int x = 0x25;
int i, y = x;

for (i = 0; i < 4; i++) {
y = y | (y << 8);
}
printf("y = %#x ", y );

return 0;
}

Comment hidden because of low score. Click to expand.
-2
of 2 vote

what if I do it like this :)
int convert(int x) {
x=0x25252525;
return x;
}

Comment hidden because of low score. Click to expand.
0

This question is either incomplete or wrong. every approach is wrong you cant convert one constant to another constant.
if you ask to convert a number into another then there would be infinite number of ways of doing that. like convert 5 into 10
you can say 5+5=10, 5x2=10, 5+20-15=10.

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.

### 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.