Code Infinity

SAVE THE EARTH.............

Friday, October 24, 2008

understand bitwise operator in c++...

Well, a bit confusing, bt still very usefull. Bitwise operator if used properly can be very handy.
Bt before anything you have first understand it...
You all must have been familiar with AND , OR ,NOT operations in boolean algebra.
i.e 1 OR 0 = 1, 1 AND 0 = 0 etc..
Bitwise operator works in a similliar manner..
Now look at the following code snippet,

int i= 0x1;
if(i & 0x1)
cout<<"true";

Now, you must be wondering what would be the result..
I will say output will show true.. bt how.
1 & 1 = 1
thus (i & 0x1) will result 1, which means true.
So, now you must have a little bit idea of bitwise operator..
Use it in your codes to master it... 


0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home