Are you using any interrupts and if so of which type, pure ASM, DT-INTS with PBP ISR etc?

Perhaps PBP uses an internal variable when inverting and that variable gets corrupted by some other code (as in an interrupt).

I'm with Richard on this, to prove to yourself that is, or isn't, the actual inverting that is the problem you need to write a fully compilable snippet of code that shows this happening.

Richards code below shows (I think) the ~operator working but not really, at least not that I can see, in the exact way you're using it. Ie inverting the value within an array and writing the value back to the same location in the array. If there IS a problem with ~operator then you shouldn't have too much of a problem writing a small code snippet that the rest of use can verify.

Load an array up with values, print it out. Invert one of the values, print it out.
Don't use Bluetooth connections and android apps and other "weird" things, use a simple wired connection back to a terminal program.

/Henrik.