Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. //returns the bit value of n on the p position
  2. int seeBit(int n, unsigned int p)
  3. {
  4.     //n(2) = Bn/Bn-1/Bn-2/.../B2/B1/B0
  5.     if(n & (1 << p))
  6.         return 1;
  7.     else return 0;
  8. }
  9.  
  10. //sets the p bit on or off
  11. void setBit(int *n, unsigned int p, unsigned int status)
  12. {
  13.     if(status)
  14.         *n |= (1 << p);
  15.     else
  16.         *n &= ~(1 << p);
  17. }
  18.  
  19. //negates the p bit
  20. void invBit(int *n, unsigned int p)
  21. {
  22.     (*n) ^= (1 << p);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement