c++ << ???

in c++ what does << mean
for example

unsigned long mask = 1 << anothVariable;

3 Responses to “c++ << ???”

  • Ken B:

    The "<<" is simply an operator, like "+" or "-".

    In this case, it’s a bitwise left shift, and "1 << n" will give you a binary value with the n’th bit set.

    (Un)fortunately, in C++, operators can be overloaded. That is, given different meanings than the built-in operator, so you can have things like:

    cout << "This is some text.";

    which has nothing to do with bit-shifting.

  • covinher:

    bitwise left shift, in simplest form (like for constants) x<<n multiplies by x by 2-to-the-n-power.

    http://en.wikipedia.org/wiki/Arithmetic_shift

  • Gunmaster Snow:

    The << and >. symbols are actually operators, like + and * are operators. The symbol is the output operator< and >> is the input operator. As you know, the variable to the right of the << or >> operator is what is being input of output. So what are cout and cin? well, cout is the destination of the output, and cin is the source of the input..
    i hope this helps =]

Leave a Reply