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.
- Flipping bits
- Discussions
Flipping bits
Flipping bits
Sort by
recency
|
341 Discussions
|
Please Login in order to post a comment
JAVA code
return n ^ 0xFFFFFFFFL; }
c++ solution. The key is that NOT operation on bits does the 'flipping'. And since we operate on unsigned positive ints, gotta add 2 times INTMAX+1 to avoid negative numbers.
C makes this trivial using the XOR operator:
return(UINT32_MAX^n);
C++ Solution