Advertisement
TwITe

Untitled

Aug 6th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. //&& для булевых переменных
  2. bool log_and (bool cond1, bool cond2) {
  3.     if (cond1) {
  4.         if (cond2) {
  5.             return true;
  6.         }
  7.     }
  8.     return false;
  9. }
  10.  
  11. //& для булевых переменных
  12. int bit_and_for_bool (bool cond1, bool cond2) {
  13.     if (!cond1) {
  14.         if (!cond2) {
  15.             return false;
  16.         }
  17.         return false;
  18.     }
  19.     else {
  20.         if (!cond2) {
  21.             return false;
  22.         }
  23.         return true;
  24.     }
  25. }
  26.  
  27. //& аналог оператора &
  28. int bit_and_for_int_f2(int a, int b) {
  29.     const int size = sizeof(int) * 8;
  30.     bitset <size> number_one(a);
  31.     bitset <size> number_two(b);
  32.     bitset <size> number;
  33.     for (int i = size - 1; i >= 0; i--) {
  34.         if (number_one[i] == 1) {
  35.             if (number_two[i] == 1) {
  36.                 number[i] = 1;
  37.             }
  38.         }
  39.         else {
  40.             number[i] = 0;
  41.         }
  42.     }
  43.     return (int)number.to_ulong();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement