# bit manipulation

• 03-04-2009
dsupriya
bit manipulation
Hi,

I would like to do the following:

(i) from a 24bit hexadecimal mask, I would like to know which bit in ON (1).

(ii) from a 16 bit data word I would like to read the 12 bits (starting from LSB) and 13-16 bits separately

How do I do this?
• 03-04-2009
matsp
What DO YOU think?

--
Mats
• 03-04-2009
nacho4d
for masking bits... why don't use exclusive disjunction? (if c does not implement it it could be easily implemented with logic or "|" and logic and "&" operators)

your could compare your result with something like pow(2,n) to know if right n-most bit is on or not.

Regards
• 03-04-2009
dsupriya
anybody has a piece of code?
• 03-04-2009
iMalc
If you're a beginner then you'll learn more by working out the answer yourself, or at the very least looking it up yourself online.
If not, then you'll already know how to do it.

We don't help people cheat if that's what you're after.
• 03-05-2009
dsupriya
Thanks!!

But I thought having a piece of simple code to look at is a process of learning and posting a question in a forum is the way to learn from internet.

But anyway, thanks again for redefining "learning" and "cheating".

Be happy always!
• 03-05-2009
matsp
Right, there was two purposes to my original "what do you think":
1. How much do you actually know about the subject.
2. You need to learn by doing, not by copying.

I may very well be able to post a piece of example code, but without knowing the level of your understanding, the example code may not be meaningful to you.

--
Mats
• 03-05-2009
Snafuist
Quote:

Originally Posted by matsp
I may very well be able to post a piece of example code, but without knowing the level of your understanding, the example code may not be meaningful to you.

Let's have a test:

Code:

`((1 << b) - 1) << c`
Greets,
Philip
• 03-05-2009
tabstop
Quote:

Originally Posted by dsupriya
Thanks!!

But I thought having a piece of simple code to look at is a process of learning and posting a question in a forum is the way to learn from internet.

But anyway, thanks again for redefining "learning" and "cheating".

Be happy always!

Posting a question in a forum is indeed a way to learn from the internet.

Note the complete absence of "having someone write your code for you".