but I can't quite get right the flipping of the remaining 7 bits
I agree with dave_the_m that some more examples would be best. But to answer this part of the question, you can mask the value to only get the lower 7 bits with $val & 0x7F, and then flip the lower 7 bits with an XOR, i.e. $val ^ 0x7F, put together that's my $y = ($x & 0x7F)^0x7F;.
$z = $x & (1 << 7);
BTW, since you're probably just looking to get a true/false value from this, you don't need the bit shift: $x & 0x80 is enough to tell you if the high bit is set or not, since the return value will be either 0 (false) or 0x80 (true). Update: Actually, never mind - the compiler is of course smart enough to optimize (1 << 7) into 128. I personally prefer 0x80 or 0b1000_0000 over (1 << 7), which is why I tripped over this at first, but TIMTOWTDI.