Sort by

recency

|

782 Discussions

|

  • + 0 comments

    Flipping bits is a core concept in computing, where binary values (0s and 1s) are reversed. This process is used in encryption, data compression, and error correction. For developers or businesses dealing with such low-level operations, having a powerful server environment is essential. If you're targeting the Asian region, especially for performance-intensive tasks, vps hosting in thailand by Navicosoft offers reliable, secure, and high-speed VPS solutions that can fully support such technical needs.

  • + 0 comments
    int("".join(["1" if i == "0" else "0" for i in bin(n)[2:].rjust(32, "0")]), 2)
    
  • + 0 comments

    long flippingBits(long n) { return 4294967295-n; }

  • + 0 comments

    Here is my c++ solution, you can watch the video explanation here : https://youtu.be/eZ0lTIzOjhQ

    V1

    long flippingBits(long n) {
        long result = 0;
        for(int i = 31; i >= 0; i--) {
            if(n >= pow(2, i)){
                n -= pow(2,i);
            }
            else result += pow(2, i);
        }
        return result;
    }
    

    V2

    long flippingBits(long n) {
        return 4294967295 ^ n;
    }
    
  • + 0 comments

    def flippingBits(n): num = ~n return 4294967296 + num