I have the following snippet:
int n = 10;
int k = n>>1;
std::cout<<k;
This prints 5.
I want k to be the last digit in binary representation of n. Like bin(n) = 1010 So, I want k to be 0.
I understand long methods are possible. Please suggest a one liner if possible.
Edit:
After going through the comments and answers, I discovered that there are various ways of doing that.
Some of them are:
k = n%2
k = n&1
Thanks to all those who answered the question. :)