The Utility of the OR Bitwise Operator
Get introduced to the utility of the OR bitwise operator.
We'll cover the following...
Switch a bit on using OR
The OR bitwise operator is used to turn on the bit. See the code given below!
Press + to interact
C
#include <stdio.h># define BV(x) ( 1 << x)int main( ){// Declare variablesunsigned char n ;unsigned int val ;n = 150;// Check whether the 3rd bit is on or offif ( ( n & BV(3) ) == BV(3) )printf( "3rd bit is on\n" ) ;else{printf ( "3rd bit is off\n" ) ;// Put on 3rd bitn = n | BV(3) ;printf ( "%d\n", n ) ;}}
To turn on the bit, first, we have to select the appropriate mask value based on the value that should be turned on. If you want to turn on the ...
Ask