there was a question to flip all the bits of an integer . I thought to use ~ operator but this gave me wrong ans whe negation operator does change the bit to 0 or 1 accordingly ? kindly explain
I have a doubt?
@ritik_99 yes ~ operator changes all the 0s to 1 and vice versa. Can you please share the question in which you got wrong answer so I can further help you?
Actually when i declared the integer as unsigned it gave the correct ans ? Does this work for unsigned int only ?
@ritik_99 do you know about the 2s complement storage of integers? Negative numbers are stored in 2s complement’s form, hence it might give unexpected result when working with signed integers.
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.