cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
bit manipulation
bit manipulation
Sep 27, 2009 at 10:14am UTC
Null
(957)
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?
Sep 27, 2009 at 11:01am UTC
screw
(145)
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.