fork(2) download
  1. #include <stdio.h>
  2.  
  3. int weight(int a){
  4. int r = 0;
  5. while(a){
  6. a &= (a-1);
  7. ++r;
  8. }
  9. return r;
  10. }
  11.  
  12. int LFSR(){
  13. static unsigned long ShiftRegister = 1;
  14.  
  15. ShiftRegister = (((((ShiftRegister >> 31)
  16. ^(ShiftRegister >> 6)
  17. ^(ShiftRegister >> 4)
  18. ^(ShiftRegister >> 2)
  19. ^(ShiftRegister >> 1)
  20. ^ShiftRegister))
  21. & 0x00000001) << 31)
  22. | (ShiftRegister >> 1);
  23. return ShiftRegister & 0x00000001;
  24. }
  25.  
  26. void main(void){
  27. int a = 7;
  28. int c = weight(a);
  29. printf("%d\n", c);
  30.  
  31. int i;
  32. for(i = 0; i < 8; i++)
  33. printf("%d ", LFSR());
  34. scanf("%d", &a);
  35. }
Runtime error #stdin #stdout 0s 2012KB
stdin
Standard input is empty
stdout
3
0 0 0 0 0 0 0 0