Adobe Interview Question


Country: United States




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

#include<iostream>

using namespace std;

int main()
{
int a;
cout<<"enter a positive number..."<<endl;
cin>>a;
cout<< (a+64 &(~63));
return 0;
}

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

Can u pls explain the logic......

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

I like Vicks solution better, it uses only use three operations (instead of 4):

return ((n>>6)+1)<<6;

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

@anuj
lets understand by simple example:
suppose 90 is the number after which we have to find multiple of 64
than binary of 90 is 01011010 and 90+64=154 whose binary is 10011010
now you can see after adding 64 to 90 the next bit(8th bit is set)
when you '&' it with `~63' i.e. 11000000 it gives u value 10000000 which is 128. so the trick is to add 64 to the value so that its next bit is set. which will be remain during logical ANDING of negation of 63.

- Prateek July 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

consider input 188, 188+64 binary is 10101010 anded with ~63 (11000000) is 10000000 (256) whereas 192 is next multiple of 64
i suggest divide number by 64, add 1 to the result and shift left six times

- nik August 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

Its easy

#include<iostream>

int main(){
int k;
cin>>k;
cout<<(1+((k)/64))*64;
return 0;

}

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

your solution is right,

but the question says "with bit operation " so the former solution is more appropriate .

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

Could u please explain me what a bit operation is???

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

#include<iostream>
using namespace std;

int nextmultiple(int);

int main()
{
int n;
cin>>n;
cout<<endl<<nextmultiple(n)<<endl;

return 0;
}
int nextmultiple(int n)
{
if(n<64)return 64;
return ((n>>6)+1)<<6;
}

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

its pretty easy man... i am simply writing the algo...

int multiple64(int num){
int a=num/64;
return ((a+1)<<6);

- nayanava... April 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// with out bitwise
#include<iostream>
int main(){
int n;
cin>>n;
cout<<(1+(n/64))*64;
return 0;
}

- Dinesh Tolani March 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

k=input/64
return 64<<(k+1)

- Shakti April 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int multiple64(int n){
	int mask=1<<31,pos=0;
	int i=0;
	for(i=0;i<32;i++){
		if(mask&n>0)break;
	}
	pos=32-i;
	return (pos>6)?1<<(pos+1):64;
}

- Karthik Vvs April 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

k=input/64
return 64<<(k)

- anonymous July 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<stdint.h>
using namespace std;
#include<conio.h>
#include <bitset>
main()
{int n;
cin>>n;
n= n>>6;
n=n+1;
n= n<<6;

cout<<n;



getch();
return 0;
}

- saraf2206 October 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a + (64 - (a & 0x3f))

- sumit November 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Use the following code to get the answer.

#include <stdio.h>
#include <math.h>

int main ()
{
  float param, result;
  scanf("%f", &param);
  int leftmostsetbit = (int)log2(param);
  int answer = 1;
  answer =  answer << (leftmostsetbit+1);
  if(answer < 64)
            printf("64\n");
  else
            printf("%d\n", answer);
  getch();
  return 0;
}

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

@aasshishh the question is "next multiple of 64 that follows it" so it should be 64,128,192,256...
but for your program, if I enter 130, I am getting 256 as output...!!!

please correct me if my understanding is wrong...

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

You are right. I understood the question wrong.

- aasshishh March 22, 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