0

What is the extraction operator doing? I have never seen it used this way.

void DecimalToBinary(int decimal)
{
int remainder;

if(decimal <= 1)
    {
    cout << decimal;
    return;
}

remainder = decimal % 2;

/*----->>>*/ DecimalToBinary(decimal >> 1);/*what is the extraction operator doing?*/
cout << remainder;
 }
rogerthat
  • 1,805
  • 4
  • 20
  • 34
  • It's a right shift, not an extraction. http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fbitshe.htm – Joe Feb 25 '13 at 00:08
  • 2
    There are lots of things about C++ that suck, and "operator overloading" is arguably one of them. The original meaning of operator ">>", from C, is "binary right shift": [Absolute Beginners Guide to Bit Shifting](http://stackoverflow.com/questions/141525/absolute-beginners-guide-to-bit-shifting) –  Feb 25 '13 at 00:10

3 Answers3

3

It was a bitshift operator long before it was an extraction operator.

user229044
  • 232,980
  • 40
  • 330
  • 338
3

It is not an extraction operator - it is a bitwise shift - or "divide by two" (although it may not work correctly for negative numbers).

The "extraction operator" is just borrowing one of the less common operators in the C language to do something completely different with it.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
2

This is the bitshift operator, in this case it shifts the whole value to the right by one bit.

E.g.:

 13 >> 2

 01101 
 00110 //right by one
 00011 //repeat

 = 3
Adam Schmidt
  • 452
  • 2
  • 15