abinash_hstu

Bit Operation

Jan 15th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. //Abinash Ghosh(Om)
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cctype>
  5. #include <cmath>
  6. #include <cstring>
  7. #include <climits>
  8. #include <iostream>
  9. #include <iomanip>
  10. #include <vector>
  11. #include <list>
  12. #include <stack>
  13. #include <queue>
  14. #include <map>
  15. #include <set>
  16. #include <string>
  17. #include <utility>
  18. #include <sstream>
  19. #include <algorithm>
  20. using  namespace  std;
  21.  
  22. #define PI acos(-1.0)
  23. #define MAX 10000007
  24. #define EPS 1e-9
  25. #define mem(a,b) memset(a,b,sizeof(a))
  26. #define gcd(a,b) __gcd(a,b)
  27. #define pb push_back
  28. #define mp make_pair
  29. #define x first
  30. #define y second
  31. #define Sort(x) sort(x.begin(),x.end())
  32. #define FOR(i, b, e) for(int i = b; i <= e; i++)
  33. #define pr(x) cout<<x<<"\n"
  34. #define pr2(x,y) cout<<x<<" "<<y<<"\n"
  35. #define READ(f) freopen(f, "r", stdin)
  36. #define WRITE(f) freopen(f, "w", stdout)
  37.  
  38. typedef  long long ll;
  39. typedef  pair <int, int> pii;
  40. typedef  pair <double , double> pdd;
  41. typedef  pair <ll , ll > pll;
  42. typedef  vector <int> vi;
  43. typedef  vector <pii> vpii;
  44. typedef  vector <ll > vl;
  45. //int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
  46. //int dx[]={1,1,0,-1,-1,-1,0,1};
  47. //int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
  48. //int dx[]={2,1,-1,-2,-2,-1,1,2};
  49. //int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
  50.  
  51. int setbit(int  N,int pos){return N=N|(1<<pos);}
  52. bool checkbit(int N,int pos){return(bool)(N&(1<<pos));}
  53. int resetbit(int N,int pos){return N=N&~(1<<pos);}
  54.  
  55. void buildin()
  56. {
  57.     int x=28;
  58.     printf("Index of least significant bit:%d\n",__builtin_ffs(x)-1);
  59.     printf("Number of leading zeroes :%d\n",__builtin_clz(x));
  60.     printf("Index of highest set bit:%d\n",31-__builtin_clz(x));
  61.     printf("Number of trailing zeroes :%d\n",__builtin_ctz(x));
  62.     printf("Number of 1-bits:%d\n",__builtin_popcount(x));
  63.     printf("Parity:%d\n",__builtin_parity(x));
  64. }
  65.  
  66. int main()
  67. {
  68.     //READ("in.txt");
  69.     //WRITE("out.txt");
  70.     int n=3;
  71.     printf("%d",resetbit(n,0));
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment