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
|
325 Discussions
|
Please Login in order to post a comment
This is about as concise as I can make it in Scala:
def flippingBits(n): return ~n & 0xFFFFFFFF
Python 3 solution Easy to understand although not very efficient
Java Solution | One Liner ✅
Integer.MAX_VALUE gives 2147483647 which is (2^31 - 1) and is not 32 bit, it is only 31 bit as 1 bit is reserved for sign.
(long) (Math.pow(2, 32) - 1) gives 4294967295 which is (2^32 - 1) and is 32 bit, so if we xor this with n we get flipped number