How to know binary of a decimal number?

Правка en3, от Son_Nguyen, 2015-08-28 10:33:03

Hello everybody. That is my code to show binary a decimal number. It's right when a>=0 but when a<0 that can't work, infinite loop. And I don't know what wrong in this code. Can you help me to solve? Thank so much!

void bi(int a)
{
        if(a==0)
            return;
        bi(a>>1);
        cout<<(a & (1));
}

//I have a nother code and it's right in both case. However I want to know what happen with this code. Sorry for my bad English

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский Son_Nguyen 2015-08-28 10:33:03 22
en2 Английский Son_Nguyen 2015-08-28 10:32:23 16
en1 Английский Son_Nguyen 2015-08-28 10:31:53 502 Initial revision (published)