Tripti Tiwari
Which bitwise operator is suitable for checking whether a particular bit is ON or OFF?
By Tripti Tiwari in C, C++, MFC on Oct 04 2013
  • eram fatima
    Jan, 2018 29

    Bitwise AND operation is used to check whether a particular bit is on or off. For example if in 10010 you need to check if second bit (from right hand side) is on or off then you simply AND it with 00010 ..the answer will be 1 at the second bit (00010) which means that the bit is on and if the answer to bitwise AND was zero it would have meant that the bit is off.

    • 0
  • Mukesh Kumar
    Sep, 2017 4

    &

    • 0
  • Rahul Prajapat
    Jun, 2015 10

    Bitwise And operator

    • 0
  • Tripti Tiwari
    Oct, 2013 4

    Bitwise AND operator.
    Example: Suppose in byte that has a value 10101101 . We wish to check whether bit number 3 is ON (1) or OFF
    (0) . Since we want to check the bit number 3, the second operand for AND operation we choose is binary
    00001000, which is equal to 8 in decimal.
    Explanation:
    ANDing operation :
    10101101 original bit pattern
    00001000 AND mask
    ---------
    00001000 resulting bit pattern
    ---------
    The resulting value we get in this case is 8, i.e. the value of the second operand. The result turned out to be a 8
    since the third bit of operand was ON. Had it been OFF, the bit number 3 in the resulting bit pattern would have
    evaluated to 0 and complete bit pattern would have been 00000000. Thus depending upon the bit number to be
    checked in the first operand we decide the second operand, and on ANDing these two operands the result
    decides whether the bit was ON or OFF.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS