fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int FullAdder(int A, int B)
  5. {
  6. static int Cr;
  7. int S;
  8. if (A|B)
  9. {
  10. S=(A^B^Cr)&1;
  11. Cr=(A&B|Cr&(A^B))&1;
  12. return (FullAdder(A>>1, B>>1)<<1)|S;
  13. }
  14. return Cr;
  15. }
  16.  
  17. int SwapBits(int X)
  18. {
  19. return ((X&0x55555555)<<1)|((X&0xAAAAAAAA)>>1);
  20. }
  21.  
  22. int main()
  23. {
  24. printf("%d\n",FullAdder(999,1));
  25. printf("%x\n",SwapBits(0x1248));
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
1000
2184