General doubt on bits

if n is an integer then how can we get its last and rest of th e bits by the operation n % 2 and n // 2 .

Let a number x bit representation be
1 0 0 0 1 1 0 , now tell me which bit do you want in this bit representation is it 0 or 1?

The question is to check whether the no has alternating bits or not.

For that what you can do is store these bits in an array, if any ith index and (i+1)th index is equal. You print false. Else true.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.