I input a value containing an unsigned 32-bit int and I want to read bit number 19. How can I do that?
This is the input I want to read the bit from:
uint32 Input = u32AHI_DioReadInput();
int x = ???
I tried using Input(19)
and input[19]
but i didn't work cause the first one is a function and the second is considered as if it is an array. I know that I should and some of the bits and shift them but I just don't know how can I do that.
When you need to read a single bit n
, shift the number right by n
positions, and cut out all bits except the last one, like this:
int x = (Input >> n) & 1;
The >> n
shifts the content by n
bits to the right; the & 1
does a bitwise "AND" with one (its binary representation has only the lowest bit set to one, all other bits contain zeros);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments