Bitwise Operators in C - Tutorialspoint

文章推薦指數: 80 %
投票人數:10人

Bitwise Operators in C ; <> BinaryRightShiftOperator.Theleftoperandsvalueismovedrightbythenumberofbitsspecifiedbytherightoperand. A>>2=15i.e.,00001111 Example TrythefollowingexampletounderstandallthebitwiseoperatorsavailableinC− LiveDemo #include main(){ unsignedinta=60; /*60=00111100*/ unsignedintb=13; /*13=00001101*/ intc=0; c=a&b;/*12=00001100*/ printf("Line1-Valueofcis%d\n",c); c=a|b;/*61=00111101*/ printf("Line2-Valueofcis%d\n",c); c=a^b;/*49=00110001*/ printf("Line3-Valueofcis%d\n",c); c=~a;/*-61=11000011*/ printf("Line4-Valueofcis%d\n",c); c=a<<2;/*240=11110000*/ printf("Line5-Valueofcis%d\n",c); c=a>>2;/*15=00001111*/ printf("Line6-Valueofcis%d\n",c); } Whenyoucompileandexecutetheaboveprogram,itproducesthefollowingresult− Line1-Valueofcis12 Line2-Valueofcis61 Line3-Valueofcis49 Line4-Valueofcis-61 Line5-Valueofcis240 Line6-Valueofcis15 c_operators.htm PreviousPage PrintPage NextPage  Advertisements



請為這篇文章評分?