2.8.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <stdio.h>
  2. unsigned getbits(unsigned x, int p, int n);
  3. unsigned int setbits(unsigned int x,unsigned int p,unsigned int n,unsigned int y);
  4. #define MAGIC_NUMBER 33091
  5. void shotgunPrintUint(const char name[], unsigned int in);
  6. unsigned int invertBits(unsigned int x,unsigned int p,unsigned int n);
  7. unsigned getInvertBits(unsigned x, int p, int n);
  8. int rightrot(int in, int rots);
  9. int main()
  10. {
  11. shotgunPrintUint("return ",rightrot(0xdeadbeef,8));
  12. // printf("i:%u \t temp:%x \n",-1,temp);
  13. /** shifting 32 bits out is an overflow condition .*/
  14. // unsigned int temp = ~0;
  15. // unsigned int temp2=temp<<32;
  16. // printf("\t temp:%x \n",temp2);
  17. return(0);
  18. }
  19. int rightrot(int in, int rots)
  20. {
  21. return in >> rots;
  22. }
  23. /**
  24. caution if you printf, padded with 0's, a hex number of exactly 0 it will print
  25. as 0000000000 not 0x00000000
  26. */
  27. /**
  28. drop me in if you don't want to use a debugger like GDB to shotgun-debug
  29. print the value of a uint
  30. */
  31. void shotgunPrintUint(const char name[], unsigned int in)
  32. {
  33. printf(name,23423);
  34. printf("\t\t: %0#10x \n",in);
  35. return;
  36. }