This a program for conversion from decimal to binary where I have some problem to understand the binary function---
Code:#include <iostream> using namespace std; void binary(int); int main(void) { int number; cout << "Please enter a positive integer: "; cin >> number; if (number < 0) cout << "That is not a positive integer.\n"; else { cout << number << " converted to binary is: "; binary(number); cout << endl; } } void binary(int number) { int remainder; if(number <= 1) { cout << number; return; } remainder = number%2; binary(number >> 1); cout << remainder; }
Say, I would like to convert Decimal 11 to binary number. The program is running properly and giving the answer 1011. I guess that the binary function will be started with 11 and goes to
remainder = number%2;
The reminder will be 1 but the number is still 11 , right ? I did not understand the function here : binary(number >> 1) due to the ">>" sign.
Anyone explain it for me a little ?