have you seen this exp. before...

This is a discussion on have you seen this exp. before... within the C++ Programming forums, part of the General Programming Boards category; Have you seen this before .... I never see it : for(int i=5; i>0; i=i>>1){ x++; cout<< "X= "<< x<< ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Question 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?
    C++
    The best

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    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.
    C++
    The best

  3. #3
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    Binary Shift operator..look it up..I really gotta go, sorry

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    I am sorry.. but I didn't got it...

    Please can you help me with more hintsss...
    Please....
    C++
    The best

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    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.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    is there any more expretion about this

    Thanks for everybody...
    Now I know ...
    and Back to work...
    there is another program about that....

    .....
    but still .. Can you add more about these kind of expretions ...
    and if there is some hits ... URL .. etc.. Please... type it out...

    Thnks
    C++
    The best

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. floating point number comparison
    By stanlvw in forum C++ Programming
    Replies: 9
    Last Post: 04-27-2009, 02:44 PM
  2. Working with Parser Generators - Functions
    By jason_m in forum C Programming
    Replies: 1
    Last Post: 09-09-2008, 10:38 PM
  3. how do you use exp()
    By panfilero in forum C Programming
    Replies: 1
    Last Post: 09-23-2005, 04:41 PM
  4. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM
  5. Exponential function exp()
    By robquigley@hotmail.com in forum C Programming
    Replies: 2
    Last Post: 01-05-2002, 09:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21