Actually this doesn't even print all of the bits, it just returns them. And on top of that the OP is overwriting his work. There can only be one return value, so if you want to save your work, the final result must be cumulative; for example instead of returning a number, you might append the bit to a string.
The lowest bit is the only bit that is ever printed. Take note that your function in the other thread printed bits even when the if (number <= 1) was false.
Code:
#include <starship>
string binary(unsigned int x, string &retval)
{
char bit = '0' + x % 2;
if ( x <= 1 ) {
return retval + bit;
}
return binary(x / 2, retval) + bit;
}
Something like that.