Advertisement
maycod23

Bits_Basics

Jul 18th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int bintodec(string &s)
  5. {
  6. int num = 0;
  7. //32 bit;;
  8. //0 ---------31
  9. //0----------30
  10. for (int i = 0; i < s.length(); i++) {
  11. num += (1LL << i) * (s[i] - '0');
  12. }
  13. return num;
  14. }
  15.  
  16. bool powoftwo(int &num) {
  17. int count = 0;
  18. for (int i = 0; i <= 30; i++)
  19. {
  20. if ((num & (1LL << i))) count++;
  21. }
  22. if (count <= 1) return true;
  23. return false;
  24. }
  25.  
  26. void printbinary(int &x)
  27. {
  28. //32 bit representable number
  29. for (int i = 0; i < 31; i++)
  30. {
  31. if ((1LL << i)&x) cout << 1;
  32. else cout << 0;
  33. }
  34. cout << endl;
  35. }
  36. int main()
  37. {
  38. // string s; cin >> s;
  39. // //binary string
  40. // int num = bintodec(s);
  41. // cout << num << endl;
  42.  
  43.  
  44. // int num; cin >> num;
  45. // if (powoftwo(num)) {
  46. // cout << "YES" << endl;
  47. // }
  48. // else cout << "NO" << endl;
  49.  
  50.  
  51. // int x; cin >> x;
  52. // printbinary(x);
  53.  
  54.  
  55.  
  56. /////////////////property 1
  57. // int a = 5, b = 18;
  58. // int c = (a ^ b);
  59. // cout << "a^b==c" << " " << (a ^ b) << endl;
  60. // cout << "c^b==a" << " " << (c ^ b) << endl;
  61. // cout << "c^a==b" << " " << (c ^ a) << endl;
  62.  
  63.  
  64. ///////////property 2
  65. cout << (5 ^ 5 ^ 5 ^ 5) << endl;
  66. cout << (5 ^ 5 ^ 5) << endl;
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement