bit manipulation

Hello, i need some help regarding bit manipulation. My question is
How can I clear all bits in a byte except last two.

So if I have a byte like this:
11010111
it must become like this:
00000011
Any ideas how to do this?
int data = 0xd7; // 11010111
int mask = 0x3; // 00000011

int maskdNumber = data & mask;

If you use bitwise and (& symbol), then bits of result will be true where both bits of pattern are true else the result bits becomes false.

http://en.wikipedia.org/wiki/Bitwise_operation
Topic archived. No new replies allowed.