fork(3) download
  1. #include <stdio.h>
  2.  
  3. void PrintBinary(int x,int d)
  4. {
  5. char buffer[33];
  6. int index;
  7. index=0;
  8. while (d >0) {
  9. if (x & 1)
  10. buffer[index++]='1';
  11. else
  12. buffer[index++]='0';
  13. x >>= 1;
  14. d--;
  15. }
  16. while (index >0 )
  17. printf("%c",buffer[--index]) ;
  18.  
  19. printf("B\n") ;
  20. return;
  21. }
  22.  
  23. int main(int argc, char* argv[])
  24. {
  25. PrintBinary(10,6) ;
  26. PrintBinary(8,4) ;
  27. PrintBinary(32765,16) ;
  28. return 0;
  29. }
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
001010B
1000B
0111111111111101B