OR, AND Operator

前端 未结 8 2073
臣服心动
臣服心动 2021-02-13 15:30

Newbie question. How to calculate the value of the formula A f B, where f - the binary function OR or AND?

8条回答
  •  伪装坚强ぢ
    2021-02-13 16:17

    && it's operation return true only if both operand it's true which implies

    bool and(bool b1, bool b2)]
    {
     if(b1==true)
     {
       if(b2==true)
        return true;
     }
     return false;
    }
    

    || it's operation return true if one or both operand it's true which implies

    bool or(bool b1,bool b2)
    {
     if(b1==true)
     return true;
     if(b2==true)
     return true;
     return false;
    }
    

    if You write

    y=45&&34//45 binary 101101, 35 binary 100010
    

    in result you have

    y=32// in binary 100000
    

    Therefore, the which I wrote above is used with respect to every pair of bits

提交回复
热议问题