# have you seen this exp. before...

• 04-22-2002
NANO
have you seen this exp. before...
Have you seen this before ....

I never see it :
for(int i=5; i>0; i=i>>1){
x++;
cout<< "X= "<< x<< endl;
}

What is the meanning of i=i>>1
what kind of condition is that.... ? :(

does see have more about these..
I think it has,,, this is just the beginning, Right?
:rolleyes:
• 04-22-2002
NANO
this is the program...
this is the program:

#include<iostream>

int main(){
int x=0;
int y= 0;
cout<< "n= 5"<< endl;
for(int i=5; i>0; i=i>>1){
x++;
cout<< "X= "<< x<< endl;
for (int j=0; j<5;j++){
y++;
cout<< " Y= "<< y<< endl;
}
}
return 0;
}

we need to know the precise runing time of this algorithm,,,, in a big Oh notation.:o
• 04-22-2002
Xterria
Binary Shift operator..look it up..I really gotta go, sorry
• 04-23-2002
NANO
I am sorry.. but I didn't got it...
Please can you help me with more hintsss...
• 04-23-2002
MrWizard
It's a simple bit shift. Shifting the bits right 1 is equivalent to dividing by 2. If you bit shift left by 2, that is the equivalent of multiplying by 2 ^2 or 4. Usually bit shifting is faster than straight out multiplication for the processor. Although for simple numbers like 2 the compiler probably converts for you.
• 04-26-2002
NANO