Flipping bits

Sort by

recency

|

352 Discussions

|

  • + 0 comments

    JAVA solution:

    public static long flippingBits(long n) {
            return ~n & 0xFFFFFFFFL;
        }
    
  • + 0 comments

    C++ solution:

    long flippingBits(long n) {
        uint32_t num = static_cast<uint32_t>(n);
        n = ~num;
        return n;
    }
    
  • + 0 comments

    def flippingBits(n): # Write your code here x = bin(n)[2:].zfill(32) x = ''.join(['0' if i=='1' else '1' for i in x]) return (int(x,2))

  • + 0 comments
    def flippingBits(n):
        # Write your code here
        return n ^ 0xFFFFFFFF
    
  • + 0 comments

    def flippingBits(n): return n ^ 0xFFFFFFFF # XOR with a 32-bit mask