[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: setbase(2)
From: |
Maurizio Loreti |
Subject: |
Re: setbase(2) |
Date: |
21 Nov 2004 15:04:22 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
"Rai Hardeep S." <hsrai@edumail.nic.in> writes:
> Is there any equivalent to setbase(2), i.e to take output in binary
> form. As such setbase() can accept 8, 10 and 16 argument.
void toBin(
unsigned int n,
std::ostream & o = std::cout
) {
unsigned int loBit = n & 1;
if (n != loBit) toBin( n >> 1 );
o << loBit;
}
--
Maurizio Loreti http://www.pd.infn.it/~loreti/mlo.html
Dept. of Physics, Univ. of Padova, Italy ROT13: ybergv@cq.vasa.vg