/*AN NICE IMPLEMENTATION TO SEE WORKING OF ALL OPRATORS(&,|,&&,||,~ ) IN PRINTF FUNCTION OR OUT OF PRINTF FUNCTION*/
#include<stdio.h>
int main()
{
int x,y,z;
x=7,y=6,z=1;//VALUES ARE INITIALISED
printf("%d\n",~z);//VERY IMP:---THIS IS BITWISE NOT ...IT WILL INVERT THE VALUE OF Z..& THEN WILL NOT PRINT ..FE..WHICH IS MADE AFTER INVERTION OF 1...IT WILL PRINT -2 THAT IS 2'S COMLEMENT OF 1...MEANS IT TAKES <FE> AS -VE VALUE & THEN IT WILL PRINT THAT VALUE BUT BY DOING 2'S COMPLEMENT OF THAT VALUE...//
printf("%d\n",x|y&z);//NOW Z=1 ....NOT -2 ...EITHER THERE IS PRIORITY OF OPERATORS ..SEE MAN OPERATOR....BUT IN PRINTF FUNCTION MOSTLY IT EXECUTE ITS STATEMENT FROM RIGHT SO..BITWISE & OF y and z is 0000 0110 & 0000 0001=0000 0000 .....NOW OR OF x with result of y and z i.e 0000 0000 ///so x=7 means 0000 0111 | 0000 0000=0000 0111...so anything made bitwise ored with 0 ...then output will be that number....i.e. 7 in this case...
//IF ANY NUMBER MADE BITWISE AND (&) WITH 0 ..THEN OUTPUT WILL BE 0...//
printf("%d\n",x|y&~z);//~z IS INVERTION OF 1 MEANS 1111 1110...2'S COMPLEMENT OF THIS INVERTION IS TAKEN FOR THAT WE HAVE TO COMPPLEMENT IT AGAIN AND ADD 1...SO ITS COMPLEMENT IS 0000 0001 +1 =0000 0010 WILL BE 2 BCZ ITS 2'S COMPLEMENT IS TAKEN SO IT IS -2..SO WE HAVE TO MAKE & 1ST ~z=0000 0010 & y=0000 0110 =0000 0010 THIS IS ORED WITH 7
//SO 0000 0010 | 0000 0111=0000 0111 MEANS 7 ..SO OUTPUT WILL BE 7...//
printf("%d\n",x^y&z);//y&z=....y=6=0000 0110 & z=1=0000 0001 =0000 0000 bcz bits of both are getting multiplying while using bitwise & .....now 7|0=7 ...or we can say..0000 0111 |0000 0000=0000 0111=7...so 7 is printed
printf("%d\n",x|(y&&z));//1st of all y&&z...THIS IS A LOGICAL AND..NOT BITWISE...SO THE RESULT WILL BE TRUE OF FALSE ...MEANS 1 OR 0....6&&1=TRUE MEANS 1.....NOW x|1....bitwise or is used remember..so 0000 0111 | 0000 0001=0000 0111=7 is printed
printf("%d\n",x&y&&z);//I HAD SEEN IN< MAN OPERATOR>THAT PRIORITY OF BITWISE & IS MORE THAN LOGICAL AND...SO x&y=
//x=7=0000 0111 & 0000 0110=0000 0110=6 && z=1 ,so NOW LOGICAL AND OF 6&&Z=6&&1=1 ..BCZ BOTH ARE TRUE VALUES ..SO OUTPUT WILL ALSO BE TRUE ....MEANS 1 IS PRINTED...
printf("%d\n",x|y&&z);//I HAVE SEEN IN <MAN OPERATOR>THAT ..PRIORITY OF BITWISE OR IS ALSO MORE THAN LOGICAL AND...SO x|y is done 1st..x=7 y=6..so 0000 0111 | 0000 0110=0000 0111 =7 NOW THIS 7 IS MADE LOGICAL AND WITH Z=1...SO
//0000 0111 && 0000 0001=TRUE SO OUTPUT WILL BE TRUE MEANS 1..IS PRINTED
printf("%d\n",x&y|z);//priority of bitwise & is more than bitwise |...acc to <man operator> ...so 1st & is done