How to know binary of a decimal number?

Revision en1, by Son_Nguyen, 2015-08-28 10:31:53

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

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Son_Nguyen 2015-08-28 10:33:03 22
en2 English Son_Nguyen 2015-08-28 10:32:23 16
en1 English Son_Nguyen 2015-08-28 10:31:53 502 Initial revision (published)