逻辑判断

关键词 含义 等价逻辑 举例
not 逻辑非 ! not true == false
not_eq 不等于,等价于 != 5 not_eq 4 == true
and 逻辑与 && bAdded && bSetted
or 逻辑或 |

位操作和赋值

关键词 含义 等价逻辑 举例
xor 异或 ^ 4^3 == 7
xor_eq 按位异或赋值 ^= lValue ^= rValue; lValue xor_eq rValue;
bitor 按位或 or_eq
bitand 按位与 & 4 & 3 == 0
and_eq 按位与赋值 &= lValue &= rValue; lValue and_eq rValue;

代码示例:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include  <iostream>
int main(int argc,char * argv[])
{
    bool bResult  = true;

    //逻辑非
    if( not bResult)
    {
        std::cout << "Not bResult IF"<<  std::endl;
    }
    else
    {
        std::cout << "Not bResult ELSE" << std::endl;
    }

    if( !bResult)
    {
        std::cout << "!bResult IF" << std::endl;
    }
    else
    {
        std::cout<<  "!bResult else" << std::endl;
    }

    //不等于
    int x = 2;
    int y = 3;
    if( x not_eq y)
    {
        std::cout << "x not_eq y  IF" << std::endl;
    }
    else
    {
        std::cout << " x not_eq y ELSE" << std::endl;
    }

    if( x != y)
    {
        std::cout << "x != y IF " << std::endl;
    }
    else
    {
        std::cout << " x != y ELSE" << std::endl;
    }

    //按位与
    int lValue = 4;
    int rValue = 3;

    int bitAndValue = lValue bitand rValue;

    int andValue = lValue & rValue;
    std::cout  <<"lValue bitand rValue:   " << bitAndValue<<  std::endl;
    std::cout << "lValue & rValue:   "<<  andValue << std::endl;

    //按位或
    int bitOrValue = lValue bitor rValue;

    int orValue = lValue | rValue;
    std::cout  <<"lValue bitor rValue:   " << bitOrValue << std::endl;
    std::cout << "lValue | rValue:   " << orValue << std::endl;

    //逻辑判断
    bool bTrue = true;
    bool bFalse = false;

    // and  ---  &&  
    if(bTrue and bFalse)
    {
        std::cout << "bTrue and bFalse   IF"  <<std::endl;
    }
    else
    {
        std::cout << "bTrue and bFalse   ELSE"<<  std::endl;
    }

    if(bTrue && bFalse)
    {
        std::cout << "bTrue && bFalse   IF" << std::endl;
    }
    else
    {
        std::cout << "bTrue && bFalse   ELSE" << std::endl;
    }

    // or ----- ||
    if(bTrue or bFalse)
    {
        std::cout << "bTrue or bFalse   IF" << std::endl;
    }
    else
    {
        std::cout << "bTrue or bFalse   ELSE"  <<std::endl;
    }

    if(bTrue || bFalse)
    {
        std::cout  <<"bTrue || bFalse   IF"<<  std::endl;
    }
    else
    {
        std::cout << "bTrue || bFalse   ELSE" << std::endl;
    }

    // xor --- ^
    if( bFalse xor bTrue )
    {
        std::cout << "bFalse xor bTrue    IF" << std::endl;
    }
    else
    {
         std::cout << "bFalse xor bTrue   ELSE" << std::endl;
    }

    if( bFalse ^ bTrue )
    {
        std::cout << "bFalse ^ bTrue    IF"  <<std::endl;
    }
    else
    {
         std::cout << "bFalse ^ bTrue   ELSE" << std::endl;
    }


    int eqValue = 3;
    int rEqValue = 4;

    eqValue xor_eq rEqValue;
    std::cout  <<"eqValue xor_eq rEqValue  " << eqValue << std::endl;

    eqValue = 3;
    eqValue ^= rEqValue;
    std::cout  <<" eqValue ^= rEqValue  " << eqValue  <<std::endl;

    eqValue = 3;
    eqValue or_eq rEqValue;
    std::cout << "eqValue or_eq rEqValue  "  <<eqValue << std::endl;

    eqValue = 3;
    eqValue |= rEqValue;
    std::cout  <<" eqValue |= rEqValue  " << eqValue << std::endl;

    eqValue = 3;
    eqValue and_eq rEqValue;
    std::cout << "eqValue and_eq rEqValue  " << eqValue << std::endl;

    eqValue = 3;
    eqValue &= rEqValue;
    std::cout  <<" eqValue &= rEqValue  " << eqValue << std::endl;
    return 0;
}

输出:

Not bResult ELSE
!bResult else
x not_eq y  IF
x != y IF
lValue bitand rValue:   0
lValue & rValue:   0
lValue bitor rValue:   7
lValue | rValue:   7
bTrue and bFalse   ELSE
bTrue && bFalse   ELSE
bTrue or bFalse   IF
bTrue || bFalse   IF
bFalse xor bTrue    IF
bFalse ^ bTrue    IF
eqValue xor_eq rEqValue  7
eqValue ^= rEqValue  7
eqValue or_eq rEqValue  7
eqValue |= rEqValue  7
eqValue and_eq rEqValue  0
eqValue &= rEqValue  0