We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Depends how you print it. The bits are likely correct, buut the interpretation of int in cout is indeed different than interpretation of unsigned.
I.e. with int, you'd need to cast it to unsigned just for the printing, for example:
int x;
...
cout << static_cast<unsigned>(~x) << endl;
(and indeed if there is some number in the input which is greater than the max signed int, i.e. 2147483647, it will not work as well because of that - and such numbers are a valid input according to the description)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Flipping bits
You are viewing a single comment's thread. Return to all comments →
Depends how you print it. The bits are likely correct, buut the interpretation of int in cout is indeed different than interpretation of unsigned.
I.e. with int, you'd need to cast it to unsigned just for the printing, for example:
(and indeed if there is some number in the input which is greater than the max signed int, i.e. 2147483647, it will not work as well because of that - and such numbers are a valid input according to the description)