what does this code do?

This is a discussion on what does this code do? within the C++ Programming forums, part of the General Programming Boards category; I'm looking at some code I'm trying to use out of a book, but there are a couple portions of ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    26

    what does this code do?

    I'm looking at some code I'm trying to use out of a book, but there are a couple portions of it I don't understand.

    Code:
    m=1;
    for (ntmp = ntps; ntmp; ntmp >>= 1) {
             m <<= 1;
    }
    Similary,

    Code:
    mid=(1+ir) >> 1;
    Specifically, what does the >>= and <<= operators mean?

    also,

    Code:
    for (;;) {
            ----Inner loop code----
    }
    If someone could explain what exactly these three sections of code are doing, it would be appreciated.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    >> and << is "shift right operator" and "shift left operator" respectively. That is multiply by 2 or divide by 2 to the power of y where y is what's on the right of the operator >>.

    The >>= operator is the same, but short hand for x = x >> y;

    The for(; is an infinite loop (of course, the loop may have code inside it that breaks the loop itself).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 09:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

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