Flipping bits

Sort by

recency

|

175 Discussions

|

  • + 0 comments

    I read the problem and had a plan for the implementation but then had to go pick up my daughter at daycare. As I was walking there, I realized that this is just a NOT... doh!!

    Swift:

    func flippingBits(n: Int) -> Int {
        return Int(~UInt32(n))
    }
    
  • + 0 comments

    java 8

    public static long flippingBits(long n) { int a = (int) n; return Integer.toUnsignedLong(~a); }

  • + 0 comments

    He aprendido sobre el manejo de los sistemas numericos

    public static long flippingBits(long n)
        {
            string binary = Convert.ToString(n, 2).PadLeft(32, '0');
            string flipping = "";
              
            foreach(char d in binary) flipping += d == '0' ? '1' : '0';
            return Convert.ToUInt32(flipping, 2);       
        }
    
  • + 0 comments

    C++:

    long flippingBits(long n) {
        return (uint32_t)~n;
    }
    
  • + 0 comments
    def flippingBits(n):
        maxN = 4294967295
        return maxN-n