fork(9) download
  1. #include<stdio.h>
  2.  
  3. void showBit(int num, int nBit)
  4. {
  5. unsigned int temp = 1<<(nBit-1), i;
  6.  
  7. for(i=0; i<nBit; ++i)
  8. {
  9. printf("%d ", ((num&temp)?1:0) );
  10. temp = temp>>1;
  11. }
  12. printf("\n");
  13. }
  14.  
  15. int main()
  16. {
  17. int num = -1;
  18.  
  19. showBit(num, 4);
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
1 1 1 1