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;
}

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

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

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;``

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

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

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

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

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;``````

}

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

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

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

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

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;
}

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);

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;
}

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

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

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

``````public static int multiple64(int n){
int i=0;
for(i=0;i<32;i++){
}
pos=32-i;
return (pos>6)?1<<(pos+1):64;
}``````

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

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

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;
}

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

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

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);
printf("64\n");
else
getch();
return 0;
}``````

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

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

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

You are right. I understood the question wrong.

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.