Bitwise Operators

Hello,I try to learn c++ basics from this site tutorial , and I reached Bitwise Operators ( &, |, ^, ~, <<, >> ) . Well,this is the first thing I met , that I didn't understand from there,can anyone explain it to me please ?
Basically they take the bits of a number and do stuff with them. i'll try to explain through code they are pretty simple. :P

1
2
3
01010101 &
11001100 =
01000100 // if both of the bits is 1 put 1 in result 


1
2
3
01010101 |
11001100 =
11011101 // if either of the bits is 1 put 1 in result 


1
2
3
01010101 ^
11001100 = //if one of the bits is 1 put 1 in result
10011001 // wont work if both have 1 


1
2
~01010101
 10101010 //just reverse the bits 


1
2
01010101 << 4
01010000 // put 4 zeros in the start 


1
2
01010101 >> 4
00000101 // put 4 zeros in the end 
that was a really great explanation breadman. this helped me too.
thanks,I understand it now !
I made a BitFlags class some week ago for learning this, you might want to look at it as one example application of this technique.
http://dl.dropbox.com/u/1564029/BitFlagsTest.txt
Topic archived. No new replies allowed.