What is the -1 doing

Subtracting one.

Any power of two can be expressed as a 1 followed by several zeros, the number depending on the power. If you subtract one from the resulting number you get zero followed by several ones.

If you want the inverse of this, for example you have 0001 1111 and you want 1110 0000 then just take the inverse of the number. There are many ways of doing this, here are some, assume the number you want to invert is in a vaiable called b

b = ~b; // note this is a tilda not a minius

b = b ^ 0xff // exclusive or inverts all bits in a variable that have a matching one in the number you are exoring it with

b = not(b);