Flipping bits

Sort by

recency

|

166 Discussions

|

  • + 1 comment

    Solution in php:

    function flippingBits($n) {

    if (!is_array($n)) {
        return 0xFFFFFFFF - $n;
    }
    
    $ent = [];
    foreach (`$n as $`value) {
        `$ent[] =  0xFFFFFFFF - $`value;
    }
    
    return $ent;
    

    }

  • + 0 comments

    public static long GetFlippingBits(long n) { uint binary = (uint)n; return ~binary; }

  • + 0 comments

    uint binary = (uint)n; return ~binary;

  • + 0 comments

    i mean we can just return ~n & 0xFFFFFFFF.........thats it....you are all set

  • + 0 comments
    public static long flippingBits(long n) {
            // Create a mask with all bits set to 1
            long mask = 0xFFFFFFFFL; 
    
            // Flip all bits using XOR operation
            return n ^ mask;
        }