I'm using direct port reading in a project, and I need to know if a pin status changed. So the firs step was to compare a status before and after of the PORT value and I get to a binary number that gives me a 1 where the bit has changed. Now I got stuck at trying to get an "elegant" solution to a function that will work like this:
If input is 0001 the result will be 1
If input is 0100 the result will be 3
And so on...
Only one bit will be high at the time.
Is there a bitwise operator that will give me this kind of result?
Regards